AES加密 自定义密钥生成

来源:互联网 发布:caffe 数据增强 编辑:程序博客网 时间:2024/06/06 11:46
//算法private static String algorithm="AES";//自定义密钥,由uuid生成的32位字符串/** * uuid是128位整数 以16进制展现 */private static String key = UUID.randomUUID().toString().replaceAll("-","");/** * 生成密钥 * @return * @throws Exception */public static Key getKey(String strKey) throws Exception{//创建密钥生成器KeyGenerator keyGenerator = KeyGenerator.getInstance(algorithm);//初始化密钥keyGenerator.init(new SecureRandom(strKey.getBytes()));//生成密钥SecretKey getKey = keyGenerator.generateKey();        System.out.println("生成密钥:"+bytesToHexString(getKey.getEncoded ())+"----"+bytesToHexString(getKey.getEncoded ()).length());        return getKey;}

0 0
原创粉丝点击