It's really one of definition - the two mechanisms are the same.
Strictly speaking PKCS5Padding is only applicable to ciphers with a block size of 8 bytes as PKCS5 only talks about the mechanism as means of padding a block cipher with a block size of 8 bytes. In PKCS7 on the other hand the method was expanded to provide a general algorithm for introducing and removing padding in ciphers with a block size up to 255 bytes. So for example, if you want to be orthodox, while it makes sense to talk about DES with PKCS5Padding or PKCS7Padding, it only makes sense to talk about AES with PKCS7Padding.
Anything encrypted with PKCS5Padding should decrypt with PKCS7Padding. If you are seeing problems, it is not the padding that is causing them.
The block size is a property of the used cipher algorithm. For AES it is always 16 bytes.
So strictly speaking, PKCS5Padding cannot be used with AES since it is defined only for a block size of 8 bytes. I assume, AES/CBC/PKCS5Padding is interpreted as AES/CBC/PKCS7Padding internally.
The only difference between these padding schemes is that PKCS7Padding has the block size as a parameter, while for PKCS5Padding it is fixed at 8 bytes. When the Block size is 8 bytes they do exactly the same.
It's really one of definition - the two mechanisms are the same.
Strictly speaking PKCS5Padding is only applicable to ciphers with a block size of 8 bytes as PKCS5 only talks about the mechanism as means of padding a block cipher with a block size of 8 bytes. In PKCS7 on the other hand the method was expanded to provide a general algorithm for introducing and removing padding in ciphers with a block size up to 255 bytes. So for example, if you want to be orthodox, while it makes sense to talk about DES with PKCS5Padding or PKCS7Padding, it only makes sense to talk about AES with PKCS7Padding.
Anything encrypted with PKCS5Padding should decrypt with PKCS7Padding. If you are seeing problems, it is not the padding that is causing them.
The block size is a property of the used cipher algorithm. For AES it is always 16 bytes.
So strictly speaking, PKCS5Padding cannot be used with AES since it is defined only for a block size of 8 bytes. I assume, AES/CBC/PKCS5Padding is interpreted as AES/CBC/PKCS7Padding internally.
The only difference between these padding schemes is that PKCS7Padding has the block size as a parameter, while for PKCS5Padding it is fixed at 8 bytes. When the Block size is 8 bytes they do exactly the same.
PKCS7Padding 和 PKCS5Padding 区别很简单,PKCS5Padding 的 blocksize 为 8 字节,而 PKCS7Padding 的 blocksize 可以为 1 到 255 字节;
实际上 PKCS5Padding 与 PKCS7Padding 基本上也是可以通用的。
通过研读参考资料下面的参考资料可以发现两者定义的区别:
在 PKCS5Padding 中,明确定义 Block 的大小是 8 字节,而在 PKCS7Padding 定义中,对于块的大小是不确定的,可以在 1-255 之间(块长度超出 255 的尚待研究),填充值的算法都是一样的;