在使用加密模块的时候,比如javax.crypto.Cipher,会碰到padding不同的形式。在java里面规定了如下几种padding:
NoPadding: No padding.OAEPWith<digest></digest>And<mgf></mgf>Padding: Optimal Asymmetric Encryption Padding scheme defined in PKCS #1, where <digest></digest>should be replaced by the message digest and <mgf></mgf>by the mask generation function. Example: OAEPWithMD5AndMGF1Padding.
PKCS5Padding: The padding scheme described in: RSA Laboratories, "PKCS #5: Password-Based Encryption Standard," version 1.5, November 1993.
SSL3Padding: The padding scheme defined in the SSL Protocol Version 3.0, November 18, 1996, section 5.2.3.2 (CBC block cipher)
通过google查到这篇描述padding的文章讲的比较清楚:
http://www.di-mgt.com.au/cryptopad.html
不同的padding方式如下:
- Pad with bytes all of the same value as the number of padding bytes (pkcs#5)
- Pad with 0x80 followed by zero bytes
- Pad with zeroes except make the last byte equal to the number of padding bytes
- Pad with zero (null) characters
- Pad with space characters