From ff4632e0db5e76a41489889ff5d4e6bc0b046463 Mon Sep 17 00:00:00 2001
From: guyue <1721849008@qq.com>
Date: 星期五, 18 七月 2025 14:34:52 +0800
Subject: [PATCH] 更改为post

---
 src/main/java/com/linghu/utils/OpenCryptUtil.java |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/main/java/com/linghu/utils/OpenCryptUtil.java b/src/main/java/com/linghu/utils/OpenCryptUtil.java
index b48aea6..f99b583 100644
--- a/src/main/java/com/linghu/utils/OpenCryptUtil.java
+++ b/src/main/java/com/linghu/utils/OpenCryptUtil.java
@@ -3,19 +3,18 @@
 
 import cn.afocus.crypt.sign.UserSign;
 
-import cn.afocus.crypt.sign.UserSign;
 import com.alibaba.fastjson.JSON;
-import com.linghu.model.entity.User;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.PostConstruct;
+import java.nio.charset.StandardCharsets;
 
 @Component
 public class OpenCryptUtil {
 
     // 加密密钥(从配置文件读取,避免硬编码)
-    @Value("${app.crypt.secret-key}") // 长度需符合算法要求(如AES-256需32位)
+    @Value("${crypt.secret}") // 长度需符合算法要求(如AES-256需32位)
     private String secret;
 
     // 初始化向量(CBC模式需要,可选)
@@ -36,8 +35,8 @@
         try {
             // 调用 open-crypt 的加密方法(根据实际API调整)
             //user转为 json
-            String json = JSON.toJSONString(user);
-            return UserSign.gen(json, "fY9tX7vX7qH5bN2cD8eM4xD2fH7uL4xM".getBytes());
+//            String json = JSON.toJSONString(user);
+            return UserSign.gen(user, "fY9tX7vX7qH5bN2cD8eM4xD2fH7uL4xM".getBytes(StandardCharsets.UTF_8));
         } catch (Exception e) {
             throw new RuntimeException("加密失败:" + e.getMessage(), e);
         }
@@ -49,7 +48,8 @@
     public String decrypt(String token) {
         try {
             // 调用 open-crypt 的解密方法
-            return UserSign.decrypt(token, "fY9tX7vX7qH5bN2cD8eM4xD2fH7uL4xM".getBytes());
+            byte[] keyBytes = "fY9tX7vX7qH5bN2cD8eM4xD2fH7uL4xM".getBytes(StandardCharsets.UTF_8);
+            return UserSign.decrypt(token, keyBytes);
         } catch (Exception e) {
             throw new RuntimeException("解密失败:" + e.getMessage(), e);
         }

--
Gitblit v1.7.1