midhunhk
midhunhk

Reputation: 5554

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.

Upvotes: 2

Views: 552

Answers (1)

David Schwartz
David Schwartz

Reputation: 182761

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.

Upvotes: 1

Related Questions