最近用AES加密的时候,结果在解密的时候报如下的错误.
javax.crypto.BadPaddingException: Given final block not properly padded
at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:975)
at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:833)
at com.sun.crypto.provider.AESCipher.engineDoFinal(AESCipher.java:446)
at javax.crypto.Cipher.doFinal(Cipher.java:2165)
后来一查才知道 windows linux 在使用AES的时候需要注意.
下面是解决办法
https://wenku.baidu.com/view/b968921514791711cc791778.html
//防止linux下 随机生成key
SecureRandom secureRandom = SecureRandom.getInstance(“SHA1PRNG” );
secureRandom.setSeed(keycontent.getBytes());
// 根据密钥初始化密钥生成器
kgen.init(keyNum, secureRandom);