AES在windows下正常加解密,Linux下加密正常,解密异常(javax.crypto.BadPaddingException: pad block co

简介: AES在windows下正常加解密,Linux下加密正常,解密异常(javax.crypto.BadPaddingException: pad block co

avax.crypto.BadPaddingException: pad block corrupted 异常,恶心了我半个小时。

废话不多说,上代码

将加密key转为byte数组片段

KeyGenerator keygen=KeyGenerator.getInstance("AES");
SecureRandom securerandom = new SecureRandom(tohash256Deal(key)); 替换为下面的两行
keygen.init(weishu, securerandom);


/**
 * SecureRandom 实现完全随操作系统本身的內部状态,
 * 除非调用方在调用 getInstance 方法之后又调用了 setSeed 方法;
 * 该实现在 windows 上每次生成的 key 都相同,
 * 但是在 solaris 或部分 linux 系统上则不同。
 * 所以  SecureRandom securerandom = new SecureRandom(tohash256Deal(key)); 替换为下面内容
 * 以适应linux的变化
 */

  SecureRandom securerandom = SecureRandom.getInstance("SHA1PRNG" );
  securerandom.setSeed(tohash256Deal(key));

其他地方不变,即可解决问题。

目录
相关文章
|
5月前
|
开发框架 监控 安全
Windows Defender 导致 Web IIS 服务异常停止排查
某日凌晨IIS服务异常停止,经查为Windows Defender安全补丁KB2267602触发引擎更新,导致系统资源波动,进而引发应用池回收。确认非人为操作,系统无重启。通过分析日志与监控,定位原因为Defender更新后扫描加重负载。解决方案:将IIS及.NET相关路径添加至Defender排除列表,避免业务影响。
650 116
|
5月前
|
安全 Linux 生物认证
Nexpose 8.25.0 for Linux & Windows - 漏洞扫描
Nexpose 8.25.0 for Linux & Windows - 漏洞扫描
235 0
Nexpose 8.25.0 for Linux & Windows - 漏洞扫描
|
5月前
|
安全 Linux iOS开发
Binary Ninja 5.1.8104 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
Binary Ninja 5.1.8104 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
553 53
Binary Ninja 5.1.8104 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
|
5月前
|
安全 Linux 生物认证
Nexpose 8.24.0 for Linux & Windows - 漏洞扫描
Nexpose 8.24.0 for Linux & Windows - 漏洞扫描
297 17
Nexpose 8.24.0 for Linux & Windows - 漏洞扫描
|
5月前
|
Linux API iOS开发
Binary Ninja 4.2.6455 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
Binary Ninja 4.2.6455 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
393 14
Binary Ninja 4.2.6455 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
|
5月前
|
SQL 安全 Linux
Metasploit Pro 4.22.8-20251014 (Linux, Windows) - 专业渗透测试框架
Metasploit Pro 4.22.8-20251014 (Linux, Windows) - 专业渗透测试框架
291 1
Metasploit Pro 4.22.8-20251014 (Linux, Windows) - 专业渗透测试框架
|
5月前
|
Linux 网络安全 iOS开发
Metasploit Framework 6.4.95 (macOS, Linux, Windows) - 开源渗透测试框架
Metasploit Framework 6.4.95 (macOS, Linux, Windows) - 开源渗透测试框架
505 1
Metasploit Framework 6.4.95 (macOS, Linux, Windows) - 开源渗透测试框架
|
6月前
|
安全 Linux 网络安全
Metasploit Pro 4.22.8-2025091701 (Linux, Windows) - 专业渗透测试框架
Metasploit Pro 4.22.8-2025091701 (Linux, Windows) - 专业渗透测试框架
427 2
Metasploit Pro 4.22.8-2025091701 (Linux, Windows) - 专业渗透测试框架
|
6月前
|
JSON 安全 Linux
Nexpose 8.22.0 for Linux & Windows - 漏洞扫描
Nexpose 8.22.0 for Linux & Windows - 漏洞扫描
228 1
Nexpose 8.22.0 for Linux & Windows - 漏洞扫描
|
6月前
|
Linux 网络安全 iOS开发
Metasploit Framework 6.4.90 (macOS, Linux, Windows) - 开源渗透测试框架
Metasploit Framework 6.4.90 (macOS, Linux, Windows) - 开源渗透测试框架
479 1
Metasploit Framework 6.4.90 (macOS, Linux, Windows) - 开源渗透测试框架