|
|
ruby des encrypt
I'm trying to using ruby des encrypt ,
in php(some gives me )
function encrypt($input) {
$size = mcrypt_get_block_size('des', 'ecb');
$input = $this->pkcs5_pad($input, $size);
$key = $this->key;
$td = mcrypt_module_open('des', '', 'ecb', '');
$iv = @mcrypt_create_iv (mcrypt_enc_get_iv_size($td),
MCRYPT_RAND);
@mcrypt_generic_init($td, $key, $iv);
$data = mcrypt_generic($td, $input);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
$data = base64_encode($data);
return $data;
}
function pkcs5_pad ($text, $blocksize) {
$pad = $blocksize - (strlen($text) % $blocksize);
return $text . str_repeat(chr($pad), $pad);
}
or in java
public String encrypt(String input) throws Exception {
return base64Encode(desEncrypt(input.getBytes()));
}
public static String base64Encode(byte[] s) {
return new Base64Encoder().encode(s);
}
public byte[] desDecrypt(byte[] encryptText) throws Exception {
byte rawKeyData[] = desKey;
DESKeySpec dks = new DESKeySpec(rawKeyData);
SecretKeyFactory keyFactory =
SecretKeyFactory.getInstance("DES");
SecretKey key = keyFactory.generateSecret(dks);
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.DECRYPT_MODE, key);
byte encryptedData[] = encryptText;
byte decryptedData[] = cipher.doFinal(encryptedData);
return decryptedData;
}
how can i translate this into ruby?
require 'openssl'
require 'Base64'
c = OpenSSL::Cipher::Cipher.new("des")
c.encrypt
c.key = "4dddb3b191a1c2d8ea1sxcv23"
#or c.pkcs5_keyivgen("4dddb3b191a1c2d8ea1sxcv23")
e = c.update("hellcatjack:111111")
e << c.final
puts Base64.encode64(e)
it's not the same as php...
--
Posted via http://www.ruby-forum.com/.
|
|
0
|
|
|
|
Reply
|
Dianhui
|
4/27/2010 1:00:38 PM |
|
Hi,
Did you try other kind of DES encryption in Ruby ?
e.g:
c = OpenSSL::Cipher::Cipher.new('DES-EDE3-CBC')
In order to know the different kind of alorithms, type:
[15:44] pierre > openssl
OpenSSL> help
openssl:Error: 'help' is an invalid command.
Standard commands
asn1parse ca ciphers crl crl2pkcs7
dgst dh dhparam dsa dsaparam
enc engine errstr gendh gendsa
genrsa nseq ocsp passwd pkcs12
pkcs7 pkcs8 prime rand req
rsa rsautl s_client s_server s_time
sess_id smime speed spkac verify
version x509
Message Digest commands (see the `dgst' command for more details)
md2 md4 md5 mdc2 rmd160
sha sha1
Cipher commands (see the `enc' command for more details)
aes-128-cbc aes-128-ecb aes-192-cbc aes-192-ecb aes-256-cbc
aes-256-ecb base64 bf bf-cbc bf-cfb
bf-ecb bf-ofb cast cast-cbc cast5-cbc
cast5-cfb cast5-ecb cast5-ofb des des-cbc
des-cfb des-ecb des-ede des-ede-cbc des-ede-cfb
des-ede-ofb des-ede3 des-ede3-cbc des-ede3-cfb des-ede3-ofb
des-ofb des3 desx rc2 rc2-40-cbc
rc2-64-cbc rc2-cbc rc2-cfb rc2-ecb rc2-ofb
rc4 rc4-40 rc5 rc5-cbc rc5-cfb
rc5-ecb rc5-ofb
--
Posted via http://www.ruby-forum.com/.
|
|
0
|
|
|
|
Reply
|
Pierre
|
4/27/2010 1:46:29 PM
|
|
|
1 Replies
565 Views
(page loaded in 0.053 seconds)
Similiar Articles: ruby des encrypt - comp.lang.rubyI'm trying to using ruby des encrypt , in php(some gives me ) function encrypt($input) { $size = mcrypt_get_block_size('des', 'ecb'); ... RSA and AES with Java and C++.... - comp.lang.java.security ...AES with Java Technology As with DES, the new Advanced ... ... AES decrypt without PKCS padding? - comp.lang.ruby Technology As with DES, the new Advanced Encryption Standard ... AES decrypt without PKCS padding? - comp.lang.rubyAnd I tried the all-Ruby crypt gem and it seems to have issues on my system ... OpenSSL? - comp.lang.java.security ..... are using to successfully do des_ede_ecb encryption ... Password-based encryption without padding? - comp.lang.java ...If I wanted to use something which I know works without padding, such as "DES ... AES decrypt without PKCS padding? - comp.lang.ruby Encrypt/Decrypt String with RSA and ... what does encryption do - comp.text.pdf... wrapper around OpenSSL that we are using to successfully do des_ede_ecb encryption ... Excel encryption - comp.lang.ruby what does encryption do - comp.text.pdf Excel ... Base64 encode in VB6, decode in Java PROBLEM!!! - comp.lang.java ...Dim encrypted_Qstring As String objEncrpt.Algorithm.Name = CAPICOM_ENCRYPTION_ALGORITHM_DES ... Need help to decode snmp string - comp.lang.ruby Need help to decode snmp ... Triple DES Perl to Java - comp.lang.java.security... ruby AES key with raw key bytes - comp.lang.java.security generating AES 128 bit key ... Using padding in encryption - DI Management Home Page Example using Triple DES ... AES key with raw key bytes - comp.lang.java.securityEncryption Algorithm - comp.soft-sys.matlab AES key with raw ... ctd): AES and block ciphers And another algorithm, DES ... RSA public key, from XML to PEM (PHP ... lang.ruby ... ruby des encrypt - comp.lang.ruby | Computer GroupI'm trying to using ruby des encrypt , in php(some gives me ) function encrypt($input) { $size = mcrypt_get_block_size('des', 'ecb'); ... DES encryption: Java to OpenSSL to Ruby - Life In A Northern Town ...Encryption has always been an interest of mine, but I really don't have mad skillz. I must admit that I ran into a bit of difficulty in trying to figure ... 7/23/2012 12:39:58 AM
|
|
|
|
|
|
|
|
|