I need to play with some fragments of AES.
I have ciphertext c and key k. The ciphertext was encrypted using AES-CBC with the addition of IV. No indentation; plain text length is a multiple of 16.
So, I am doing this:
aes = OpenSSL::Cipher::Cipher.new("AES-128-CCB")
aes.decrypt
aes.key = k
aes.iv = c[0..15]
aes.update(c[16..63]) + aes.final
and it works fine.
Now I need to do the CBC mode manually, so I need a “simple” AES decryption of one block.
I am trying to do this:
aes = OpenSSL::Cipher::Cipher.new("AES-128-ECB")
aes.decrypt
aes.key = k
aes.iv = c[0..15]
aes.update(c[16..31]) + aes.final
And he fails with
in `final': bad decrypt (OpenSSL::Cipher::CipherError)
How should I do it?
source
share