|
|
|
@ -103,11 +103,14 @@ public class DecriptTest { |
|
|
|
|
SecretKey secretKey = kgen.generateKey(); |
|
|
|
|
byte[] enCodeFormat = secretKey.getEncoded(); |
|
|
|
|
SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES"); |
|
|
|
|
Cipher cipher = Cipher.getInstance("AES");// 创建密码器
|
|
|
|
|
// 创建密码器
|
|
|
|
|
Cipher cipher = Cipher.getInstance("AES"); |
|
|
|
|
byte[] byteContent = content.getBytes("utf-8"); |
|
|
|
|
cipher.init(Cipher.ENCRYPT_MODE, key);// 初始化
|
|
|
|
|
// 初始化
|
|
|
|
|
cipher.init(Cipher.ENCRYPT_MODE, key); |
|
|
|
|
byte[] result = cipher.doFinal(byteContent); |
|
|
|
|
return result; // 加密
|
|
|
|
|
// 加密
|
|
|
|
|
return result; |
|
|
|
|
} catch (NoSuchAlgorithmException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} catch (NoSuchPaddingException e) { |
|
|
|
@ -140,10 +143,13 @@ public class DecriptTest { |
|
|
|
|
SecretKey secretKey = kgen.generateKey(); |
|
|
|
|
byte[] enCodeFormat = secretKey.getEncoded(); |
|
|
|
|
SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES"); |
|
|
|
|
Cipher cipher = Cipher.getInstance("AES");// 创建密码器
|
|
|
|
|
cipher.init(Cipher.DECRYPT_MODE, key);// 初始化
|
|
|
|
|
// 创建密码器
|
|
|
|
|
Cipher cipher = Cipher.getInstance("AES"); |
|
|
|
|
// 初始化
|
|
|
|
|
cipher.init(Cipher.DECRYPT_MODE, key); |
|
|
|
|
byte[] result = cipher.doFinal(content); |
|
|
|
|
return result; // 加密
|
|
|
|
|
// 加密
|
|
|
|
|
return result; |
|
|
|
|
} catch (NoSuchAlgorithmException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} catch (NoSuchPaddingException e) { |
|
|
|
|