zoukankan      html  css  js  c++  java
  • java加密算法-AES

    public class AESUtil {
        public static void main(String[] args){
            jdkAES("12345623423432423S");
        }
        public static void jdkAES(String str){
            try {
            SecureRandom random = new SecureRandom();
            byte[] salt = random.generateSeed(8);
            PBEKeySpec pkey=new PBEKeySpec(str.toCharArray());
                SecretKeyFactory factory = SecretKeyFactory.getInstance("PBEWITHMD5andDES");
                Key key = factory.generateSecret(pkey);
                Key key2 = factory.generateSecret(pkey);
            
                System.out.println("KEY:"+key.serialVersionUID);
                System.out.println("KEY2:"+key2.serialVersionUID);
            
            PBEParameterSpec pbets = new PBEParameterSpec(salt,100);
            Cipher c = Cipher.getInstance("PBEWITHMD5andDES");
            c.init(Cipher.ENCRYPT_MODE, key,pbets);
            byte[] result = c.doFinal(str.getBytes());
            System.out.println(Base64.encodeBase64String(result));
            
            
            c.init(Cipher.DECRYPT_MODE, key,pbets);
            result = c.doFinal(result);
            System.out.println(new String(result));
            
            
            
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        
    }
  • 相关阅读:
    2021 发工资咯:)
    HDU-2021
    HDU-2020
    HDU-2019
    HDU-2018
    HDU-2017
    HDU-2016
    HDU-2015
    HDU-2014
    HDU-2013
  • 原文地址:https://www.cnblogs.com/syscn/p/7742262.html
Copyright © 2011-2022 走看看