« Ruby strings are NOT immutable | Main | Rails Mysql driver fedora core 6 and ssh tunneling »

November 13, 2007

Comments

blonk

"I chose AES128 (Also called Rijndael)"

That's (at the very least) misleading.

AES has a fixed block length of 128 bits. The key length, on the other hand, can be 128, 192, or 256. "AES-128" means "AES with a key length of 128 bits".

Meanwhile, neither the block length nor the key length of Rijndael is fixed. "AES" means "Rijndael with a block length of 128 bits".

So "AES-128" means "Rijndael with a block length of 128 bits and a key length of 128 bits".

So, yes, in some sense it's true that "AES-128" is "Rijndael". But it's not true that "AES-128" MEANS "Rijndael".

For example, "AES-256" is also "Rijndael". And it also doesn't MEAN "Rijndael". It means "Rijndael with a block length of 128 bits and a key length of 256 bits".

Barry Cornelius

The Ruby Decrypt code needs the following two lines:
key = 'abcdefgh01234567'
rijndael = Crypt::Rijndael.new( key, 128, 128 )

Barry Cornelius

One other thing. You have:
If you encrypted multiple 16byte blocks, you will need to split bbyte up
into 16 byte blocks before decrypting.
I think this should be:
If you encrypted multiple 16byte blocks, you will need to split b64in up
into 24 character chunks and apply decode64 to each chunk and then
apply decrypt_block to the result of the decode64.
For example, for me, the result of combining the b64 encoded strings is in params[:id]. I then do:
b64in = params[:id][ 0..23]
bbyte = Base64.decode64(b64in)
decoded_parameter = rijndael.decrypt_block(bbyte)
b64in = params[:id][24..47]
bbyte = Base64.decode64(b64in)
decoded_parameter += rijndael.decrypt_block(bbyte)
The variable decoded_parameter finishes up with 32 characters.

By the way, thanks for blogging about this. Your code was very helpful: my PHP script encrypts some information and then redirects to a Rails application that successfully decrypts that information.

AC

I noticed you stated, "...at the end, combine the b64 encoded strings together.". What do you mean by that? How do I combine? Simply just append the strings together?

The comments to this entry are closed.