解決linux服務器下AES解密異常、相同內容每次加密結果都不同


現象描述

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專用密鑰
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM