From 13b31b2ca2a5f8600002a042b536c9d5529842e3 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期一, 09 三月 2026 19:21:18 +0800
Subject: [PATCH] #

---
 src/main/java/com/core/common/AesUtils.java |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 50 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/core/common/AesUtils.java b/src/main/java/com/core/common/AesUtils.java
new file mode 100644
index 0000000..1cd8964
--- /dev/null
+++ b/src/main/java/com/core/common/AesUtils.java
@@ -0,0 +1,50 @@
+package com.core.common;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import java.nio.charset.StandardCharsets;
+
+public class AesUtils {
+
+    private static final String DEFAULT_CHARSET = "utf-8";
+    private static final int DEFAULT_KEY_LENGTH = 16;
+
+    public static String encrypt(String data, String key) {
+        try {
+            if (key == null || "".equals(key) || key.length() != DEFAULT_KEY_LENGTH) {
+                return null;
+            }
+            byte[] raw = key.getBytes(StandardCharsets.UTF_8);
+            SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
+            Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
+            cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
+            byte[] encrypted = cipher.doFinal(data.getBytes(StandardCharsets.UTF_8));
+            return RadixTools.bytesToHexStr(encrypted);
+        } catch (Exception ex) {
+            return null;
+        }
+    }
+
+    public static String decrypt(String data, String key) {
+        try {
+            if (key == null || "".equals(key) || key.length() != DEFAULT_KEY_LENGTH) {
+                return null;
+            }
+            byte[] raw = key.getBytes(StandardCharsets.UTF_8);
+            SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
+            Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
+            cipher.init(Cipher.DECRYPT_MODE, skeySpec);
+            byte[] original = cipher.doFinal(RadixTools.hexStringToBytes(data));
+            return new String(original, StandardCharsets.UTF_8);
+        } catch (Exception ex) {
+            return null;
+        }
+    }
+
+    public static void main(String[] args) {
+        String key = "123456";
+        String data = "15988786205&timestamp=" + (System.currentTimeMillis() + 5000000L);
+        System.out.println(System.currentTimeMillis() + 5000000L);
+        System.out.println(encrypt(data, key));
+    }
+}

--
Gitblit v1.9.1