Page 1 of 1

A question of PKCS5

Posted: Mon Sep 17, 2018 1:22 am
by DaHuFa
Hi, everyone.
Anyone know how to calculate PKCS5 padding algorithm?
I knew that the PKCS5 padding algorithm fills bytes at the end of data until the length of total data is multiple block size.
For example, AES block size is 32 bytes. And the data is 30 bytes. The padding bytes is "0202". If the data is 28 bytes, the padding bytes will be "04040404". But If the data length is 32 bytes too, whether I should add 32bytes padding bytes?

Re: A question of PKCS5

Posted: Tue Sep 18, 2018 2:38 am
by AlexLiu
(1) AES block size is not 32 bytes, it is 16 bytes;
(2) if the data is 16 bytes, you still need to pad 0x10 to the end until its length is 32bytes;
(3) you need to pad at any case, even if the length is times of block size.

Re: A question of PKCS5

Posted: Tue Sep 18, 2018 6:19 am
by DaHuFa
yeah, I will try it.