Hi Roger,
It's hard to know for sure without a code sample, but it seems likely you are ignoring the return value from DoFinal (and/or ProcessBytes), which will tell you how many bytes were actually output by that call. The "extra" zeroes are not part of the output.

GetOutputSize can be used to find out the maximum size buffer you'll need to hold the whole output, but it is not (always) exact, so one still needs to pay attention to the ProcessBytes/DoFinal return values to track the current position in the output buffer and the actual total length.

Regards,
Pete Dettman

On 19/02/2015 3:09 am, Li, Roger wrote:

Hi Group,

I just start learning BC for AES encryption/decryption and am using AES/CBC/PKCS7PADDING for 256 bits.

BC can encrypt and decrypt text successfully, however after decryption I notice that there are always a few padding of null (0x00), which therefore fails my hash comparison. For example, suppose original input string is “1234567890”, the decrypted byte array is always {0x49,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x48,0x00,0x00,0x00,0x00,0x00,0x00}.

Why the padding is not 0x06,0x06,0x06,0x06,0x06,0x06? And is there any way to deterministically tell the padding length (could be 0) after encryption so that I can get exactly the same string before encryption?

Thanks a lot!

Roger


Reply via email to