From 2421ab222448e9db9bba26315c2bd4b7419e7a42 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期二, 14 一月 2025 15:30:27 +0800
Subject: [PATCH] 1

---
 se-modules/se-system/src/main/java/com/se/system/utils/CommonUtils.java |   33 +++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/se-modules/se-system/src/main/java/com/se/system/utils/CommonUtils.java b/se-modules/se-system/src/main/java/com/se/system/utils/CommonUtils.java
index 38d29b0..9f967a5 100644
--- a/se-modules/se-system/src/main/java/com/se/system/utils/CommonUtils.java
+++ b/se-modules/se-system/src/main/java/com/se/system/utils/CommonUtils.java
@@ -1,5 +1,8 @@
 package com.se.system.utils;
 
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import java.security.MessageDigest;
 import java.util.*;
 
 @SuppressWarnings("ALL")
@@ -10,6 +13,8 @@
 
     public CommonUtils() {
     }
+
+    private static final String key = "Secret_Ke?y_02_95";
 
     public static String validStringValue(Object object) {
         return object == null ? "" : object.toString();
@@ -221,6 +226,34 @@
         }
     }
 
+
+    public static String encrypt(String json) throws Exception {
+        byte[] keyBytes = key.getBytes();
+        MessageDigest sha = MessageDigest.getInstance("SHA-256");
+        keyBytes = sha.digest(keyBytes);
+        keyBytes = java.util.Arrays.copyOf(keyBytes, 16);
+        SecretKeySpec secretKey = new SecretKeySpec(keyBytes, "AES");
+
+        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING");
+        cipher.init(Cipher.ENCRYPT_MODE, secretKey);
+        byte[] encryptedBytes = cipher.doFinal(json.getBytes());
+        return Base64.getEncoder().encodeToString(encryptedBytes);
+    }
+
+    public static String decrypt(String encryptedJson) throws Exception {
+        byte[] keyBytes = key.getBytes();
+        MessageDigest sha = MessageDigest.getInstance("SHA-256");
+        keyBytes = sha.digest(keyBytes);
+        keyBytes = java.util.Arrays.copyOf(keyBytes, 16);
+        SecretKeySpec secretKey = new SecretKeySpec(keyBytes, "AES");
+
+        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING");
+        cipher.init(Cipher.DECRYPT_MODE, secretKey);
+        byte[] encryptedBytes = Base64.getDecoder().decode(encryptedJson);
+        byte[] decryptedBytes = cipher.doFinal(encryptedBytes);
+        return new String(decryptedBytes);
+    }
+
     public static void test(String[] args) {
         Integer a = null;
         System.out.println(isNotEmpty(a));

--
Gitblit v1.9.3