2
votes

I need to decrypt data which is encrypted by php with 'rijndael-128-cbc' algorithm.

Now I have a problem to convert php code to ruby code. ruby OpenSSL::Cipher doesn't support rijndael-128-cbc then I use "aes-128-cbc". I heard AES is based on the Rijndael cipher, so I guess I can convert decryption with rijndael-128-cbc' to AES-128-CBC.

enc = OpenSSL::Cipher.new "AES-128-CBC"
enc.encrypt
puts enc.key_len

It's output is 16

However, In php

echo mcrypt_get_key_size('rijndael-128', 'cbc')

this gets 32

Is there any difference between 'rijndael-128' and "AES-128-CBC"?

and How can I convert rijndael-128-cbc descrytion to ruby?

1

1 Answers

5
votes

I am no Ruby developer, so I can't help you with the ruby code, but I can give you a few pointers about Rijndael, and PHP's mcrypt extension ...

Yes, AES is based on Rijndael-128 and therefore Rijndael-128 and AES-128 are the same thing.

It's important to note that the number in Rijndael's variations refers to the cipher's block size, while for AES - it's the key size, so (for example) Rijndael-192 is NOT AES-192; AES always has a block size of 16 bytes or 128 bits.

That being said, Rijndael-128 can also be AES-192 and AES-256, the difference being only the key size.

As described in the PHP manual for mcrypt_get_key_size(), the function returns the maximum key length for the supplied cipher ...

AES-256 == Rijndael-128 with a 32-byte key

This is why it's returning 32. For AES-128, the key size is of course 16 - you can hardcode that.

Hopefully, that will clear it up a bit for you.