android 上AES解密是报错javax.crypto.BadPaddingException: pad block corrupted
Posted 苏小七
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了android 上AES解密是报错javax.crypto.BadPaddingException: pad block corrupted相关的知识,希望对你有一定的参考价值。
网上看到两种方法:
1.SecretKeySpec skeySpec = new SecretKeySpec(getRawKey(key), "AES");
private static byte[] getRawKey(byte[] seed) throws Exception {
KeyGenerator kgen = KeyGenerator.getInstance("AES");
SecureRandom sr = SecureRandom.getInstance("SHA1PRNG", "Crypto");
sr.setSeed(seed);
kgen.init(128, sr); // 192 and 256 bits may not be available
SecretKey skey = kgen.generateKey();
byte[] raw = skey.getEncoded();
return raw;
}
红色的部分为注意项,不能写为SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
2.Cipher cipher = Cipher.getInstance("AES"); ---------4.3以上有bug
修改为
Cipher cipher = Cipher.getInstance("AES/ECB/ZeroBytePadding");
以上是关于android 上AES解密是报错javax.crypto.BadPaddingException: pad block corrupted的主要内容,如果未能解决你的问题,请参考以下文章
Android AES加密报错处理:javax.crypto.IllegalBlockSizeException: error:1e00007b:Cipher functions:OPENSSL_in