现象描述

windows下加解密正常,部署linux服务器后解密抛出异常

javax.crypto.BadPaddingException: Given final block not properly padded

相同文本, linux下每次AES加密结果都不同

解决办法

private static SecretKeySpec getSecretKey(final String key) throws NoSuchAlgorithmException {
	// 返回生成指定算法密钥生成器的 KeyGenerator 对象
	KeyGenerator kg = KeyGenerator.getInstance(KEY_ALGORITHM);
	SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
	secureRandom.setSeed(key.getBytes());
	kg.init(128, secureRandom);
	SecretKey secretKey = kg.generateKey();
	return new SecretKeySpec(secretKey.getEncoded(), KEY_ALGORITHM);// 转换为AES专用密钥
}

相关文章:

  • 2022-02-20
  • 2022-02-09
  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
  • 2021-09-28
  • 2022-12-23
  • 2021-12-30
猜你喜欢
  • 2021-09-10
  • 2022-12-23
  • 2022-03-10
  • 2021-12-05
  • 2022-12-23
  • 2021-06-25
  • 2022-12-23
相关资源
相似解决方案