InvalidKeyException非法密钥大小我有一个在我的开发MacBookPro上运行很好的测试,但是无法在持续集成TeamCity服务器中运行。错误如下:java.security.InvalidKeyException: Illegal key size
at javax.crypto.Cipher.a(DashoA13*..)
at javax.crypto.Cipher.init(DashoA13*..)
at javax.crypto.Cipher.init(DashoA13*..)开发盒和TeamCity都使用Java1.6,我使用BouncyCastleLibrary来满足特殊AES加密的需要。守则如下:private byte[] aesEncryptedInfo(String info) throws UnsupportedEncodingException, IllegalBlockSizeException, BadPaddingException,
InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidParameterSpecException, InvalidAlgorithmParameterException,
NoSuchProviderException {
Security.addProvider(new BouncyCastleProvider());
SecretKey secret = new SecretKeySpec(CUSTOMLONGSECRETKEY.substring(0, 32).getBytes(), "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding", "BC");
cipher.init(Cipher.ENCRYPT_MODE, secret, new IvParameterSpec(VECTOR_SECRET_KEY.getBytes()));
return cipher.doFinal(info.getBytes("UTF-8"));}
3 回答
阿波罗的战车
TA贡献1862条经验 获得超6个赞
jdk1.6.0_18/lib/security
jre
jdk1.6.0_18/jre/lib/security
.
慕妹3242003
TA贡献1824条经验 获得超6个赞
CUSTOMLONGSECRETKEY...getBytes()
CUSTOMLONGSECRETKEY.getBytes(some encoding)
添加回答
举报
0/150
提交
取消