前一久,在对接支付通道时,遇到上游使用AES加密方式,对方要求加密时使用CBC模式,zeropadding填充,偏移量为0000*4(即16个0),输出十六进制,字符集使用UTF-8。
本以为也没什么问题,可到实际开发时却发现Java虽然支持AES的CBC模式,但填充方式却没有zeropadding模式。通过查看文档,先梳理一下加密算法相关的知识。
JDK1.8支持的加密算法:
Cipher Algorithm Names
The following names can be specified as the algorithm component in a transformation when requesting an instance of Cipher
.
Algorithm Name | Description |
---|---|
AES | Advanced Encryption Standard as specified by NIST in FIPS 197. Also known as the Rijndael algorithm by Joan Daemen and Vincent Rijmen, AES is a 128-bit block cipher supporting keys of 128, 192, and 256 bits. To use the AES cipher with only one valid key size, use the format AES_<n>, where <n> can be 128, 192, or 256. |
AESWrap | The AES key wrapping algorithm as described in RFC 3394. To use the AESWrap cipher with only one valid key size, use the format AESWrap_<n>, where <n> can be 128, 192, or 256. |
ARCFOUR | A stream cipher believed to be fully interoperable with the RC4 cipher developed by Ron Rivest. For more information, see K. Kaukonen and R. Thayer, "A Stream Cipher Encryption Algorithm 'Arcfour'", Internet Draft (expired), draft-kaukonen-cipher-arcfour-03.txt. |
Blowfish | The Blowfish block cipher designed by Bruce Schneier. |
DES | The Digital Encryption Standard as described in FIPS PUB 46-3. |
DESede | Triple DES Encryption (also known as DES-EDE, 3DES, or Triple-DES). Data is encrypted using the DES algorithm three separate times. It is first encrypted using the first subkey, then decrypted with the second subkey, and encrypted with the third subkey. |
DESedeWrap | The DESede key wrapping algorithm as described in RFC 3217 . |
ECIES | Elliptic Curve Integrated Encryption Scheme |
PBEWith<digest>And<encryption> PBEWith<prf>And<encryption> | The password-based encryption algorithm found in (PKCS5), using the specified message digest (<digest>) or pseudo-random function (<prf>) and encryption algorithm (<encryption>). Examples:
|