标签:div port mod and decrypt 过程 com ring vax
1 package com.pff.pff; 2 3 import java.security.SecureRandom; 4 5 import javax.crypto.Cipher; 6 import javax.crypto.KeyGenerator; 7 import javax.crypto.SecretKey; 8 import javax.crypto.spec.SecretKeySpec; 9 10 import org.apache.commons.codec.binary.Hex; 11 12 public class Aes { 13 14 private static String test = "pff"; 15 16 public static void main(String[] args) { 17 testDes(); 18 } 19 20 public static void testDes() { 21 try { 22 // 生成秘钥 23 KeyGenerator keyGenerator = KeyGenerator.getInstance("AES"); 24 keyGenerator.init(new SecureRandom()); 25 SecretKey generateKey = keyGenerator.generateKey(); 26 byte[] encoded = generateKey.getEncoded(); 27 // 秘钥转换 28 SecretKeySpec secretKeySpec = new SecretKeySpec(encoded, "AES"); 29 // DES加密过程 30 Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5padding"); 31 cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec); 32 byte[] result = cipher.doFinal(test.getBytes()); 33 System.out.println("AES加密过程结果= " + Hex.encodeHexString(result)); 34 // 解密过程 35 cipher.init(Cipher.DECRYPT_MODE, secretKeySpec); 36 byte[] result2 = cipher.doFinal(result); 37 System.out.println("AES解密过程结果= " + new String(result2)); 38 } catch (Exception e) { 39 e.printStackTrace(); 40 } 41 } 42 }
标签:div port mod and decrypt 过程 com ring vax
原文地址:https://www.cnblogs.com/wings-ff/p/9229219.html