前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Android笔记: AES解密报错javax.crypto.BadPaddingException: pad block corrupted

Android笔记: AES解密报错javax.crypto.BadPaddingException: pad block corrupted

作者头像
程思扬
发布2022-01-11 12:14:02
1.7K0
发布2022-01-11 12:14:02
举报
文章被收录于专栏:程思阳的专栏

这个问题可是让我头疼了好久,并试了很多方法在此推荐两种方法:

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”);

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/11/21 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档