|
|
@@ -1,12 +1,14 @@
|
|
|
package cn.iocoder.yudao.module.iscs.utils;
|
|
|
|
|
|
-import lombok.val;
|
|
|
import org.apache.commons.codec.binary.Hex;
|
|
|
|
|
|
import javax.crypto.*;
|
|
|
import javax.crypto.spec.IvParameterSpec;
|
|
|
-import java.security.*;
|
|
|
-import java.util.Base64;
|
|
|
+import javax.crypto.spec.SecretKeySpec;
|
|
|
+import java.security.InvalidAlgorithmParameterException;
|
|
|
+import java.security.InvalidKeyException;
|
|
|
+import java.security.NoSuchAlgorithmException;
|
|
|
+import java.security.SecureRandom;
|
|
|
|
|
|
/**
|
|
|
* 时间工具类
|
|
|
@@ -20,10 +22,12 @@ public class AES256Utils {
|
|
|
*/
|
|
|
public static String AES256DECRYPT(String plaintext) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
|
|
|
// 1. 生成256位密钥(需确保JCE无限制政策已安装)
|
|
|
- KeyGenerator keyGen = KeyGenerator.getInstance("AES");
|
|
|
+ /*KeyGenerator keyGen = KeyGenerator.getInstance("AES");
|
|
|
keyGen.init(128, new SecureRandom()); // 使用安全随机数
|
|
|
SecretKey secretKey = keyGen.generateKey();
|
|
|
-
|
|
|
+ System.out.println("1----" + secretKey);
|
|
|
+ System.out.println("2----" + secretKey.toString());*/
|
|
|
+ SecretKey secretKey = new SecretKeySpec("e3d8c4a0f72b1e9d8a5f06c3b4910d7a".getBytes(), "AES"); // "e3d8c4a0f72b1e9d8a5f06c3b4910d7a";
|
|
|
// 2. 创建Cipher实例(推荐使用CBC模式+PKCS5Padding)
|
|
|
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
|
|
|
|
|
@@ -45,7 +49,7 @@ public class AES256Utils {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public static void main(String[] args) throws Exception {
|
|
|
+ /*public static void main(String[] args) throws Exception {
|
|
|
// 1. 生成256位密钥(需确保JCE无限制政策已安装)
|
|
|
KeyGenerator keyGen = KeyGenerator.getInstance("AES");
|
|
|
keyGen.init(128, new SecureRandom()); // 使用安全随机数
|
|
|
@@ -93,6 +97,14 @@ public class AES256Utils {
|
|
|
val digest = MessageDigest.getInstance("SHA-256");
|
|
|
// String hexStr1 = Hex.encodeHexString(digest.digest(fileBytes));
|
|
|
// .sha
|
|
|
+ }*/
|
|
|
+
|
|
|
+ public static void main(String[] args) throws NoSuchAlgorithmException {
|
|
|
+ KeyGenerator keyGen = KeyGenerator.getInstance("AES");
|
|
|
+ keyGen.init(128, new SecureRandom()); // 使用安全随机数
|
|
|
+ SecretKey secretKey = keyGen.generateKey();
|
|
|
+ System.out.println("1----" + new String(secretKey.getEncoded()));
|
|
|
+ System.out.println("2----" + secretKey.toString());
|
|
|
}
|
|
|
|
|
|
}
|