版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/mingyundezuoan/article/details/81676526
AESUtil在Windows与Linux环境运行结果不同
问题描述
- 产品要求必须参数信息不暴露,在网上检索对称性加密,选择了AES的加密方式
- 常见的加密和解密算法—AES
- 开发环境代码运行正常,提交测试环境后,出现加密后的字符串解密失败的现象
- 打印加密后的日志在本地运行工具类解密失败,结果为NULL
问题定位
- 反反复复在本地联调多次依然没有问题,所以联想到是与服务器有关
- AES加密解密Windows下跟linux下结果不同的解决方案
KeyGenerator kgen = KeyGenerator.getInstance("AES");
SecureRandom random=null;
try {
random = SecureRandom.getInstance("SHA1PRNG","SUN");
} catch (NoSuchProviderException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
random.setSeed(key.getBytes());
kgen.init(128, random);码片