Search code examples
apache-flexactionscript-3flex3as3crypto

as3crypto issue


I am using the as3crypto library to get the AES algorithm working on a small project that i am doing. This is how i get the crypto function :

var cipher:ICipher = Crypto.getCipher("simple-aes-cbc", key, Crypto.getPad("pkcs5"));

As you can see, I am trying to use AES-128 with CBC and the pkcs5 padding.

If my source data is 128bytes long, the encrypted data is coming as 160bytes. Can some one tell me why this problem is coming?

Following is a small table that I compiled from a sample program.
Source string length | Encrypted string length
15 | 32
16 | 48
31 | 48
32 | 64

Is it supposed to be like this or have I made some mistake.


Solution

  • It is supposed to be like that. You asked for PKCS5 padding which always adds at least one byte of padding. And, of course, the input must be rounded up to some number of whole blocks because AES produces 16-byte chunks of output. With half a block, you cannot decrypt any of the input at all.