views:

29

answers:

3

If I write the following code

mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $raw, MCRYPT_MODE_CBC, $iv);

How to write in ruby?

+1  A: 

You can use the openssl library for this. I think what you need is here for symmetric key encryption:

http://stuff-things.net/2008/02/05/encrypting-lots-of-sensitive-data-with-ruby-on-rails/

th3sku11
+1  A: 

Here is Ruby equivalent using OpenSSL,

  cipher = OpenSSL::Cipher::Cipher.new("aes-128-cbc")
  cipher.encrypt
  cipher.key = key
  cipher.iv = iv
  encrypted = cipher.update(raw)
  encrypted << cipher.final
ZZ Coder
Thank you for answering but bad decrypt (OpenSSL::Cipher::CipherError) occured What's wrong?
ffffff
@ffffff: Can you post your code?
ZZ Coder
A: 

Can ezcrypto help? Default it uses standard aes-128-cbc but does know other algorithms.

nathanvda