0
votes

I tried this code from openssl wiki which generate a cipher text via aes-256 algorithm. The length of input plain text is 512 bytes. The length of output, however, is difference. PHP generate an output which length is 512 bytes, whereas the C generate a 528 bytes long cipher text.

why there exist such a difference and how could I use an aes-256 algorithm to encrypt an text in PHP and then decrypt it in C?

1
Removed the last part of the question, asking for examples is explicitly off topic here. - Maarten Bodewes

1 Answers

1
votes

You should look up e.g. the comments section of mcrypt_encrypt to pad the plaintext message using the PKCS#7 padding method. PHP uses zero padding up to the first value that is on the block boundary instead of the ad-hoc PKCS#7 padding method that is normally used.

The problem with zero padding is that it is not deterministic for messages that may end with a 00 byte value as this may be removed during unpadding.