首页 > 移动平台 > 详细

android 上AES解密是报错javax.crypto.BadPaddingException: pad block corrupted

时间:2017-11-21 18:21:50      阅读:2319      评论:0      收藏:0      [点我收藏+]

网上看到两种方法:

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

原文:http://www.cnblogs.com/suxiaoqi/p/7874635.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!