zoukankan      html  css  js  c++  java
  • 解决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专用密钥
    }
    

    如果觉得文章对您有用,请点下推荐。您的支持将鼓励我继续创作!

  • 相关阅读:
    linux下activemq安装
    java 线程方法join
    创建线程池
    游标储存过程
    返回结果集的储存过程
    linux 安装 reids 出错解决问题
    IDEAL 集成 jFINAL 问题
    oracle 游标
    oracle procedures
    Linux下安装Tomcat服务器
  • 原文地址:https://www.cnblogs.com/pengsn/p/13608128.html
Copyright © 2011-2022 走看看