From 0aea8bd18daaaf91e622fdcfdd81dbb2e1b4860c Mon Sep 17 00:00:00 2001
From: swb <jpy123456>
Date: Mon, 21 Oct 2024 09:01:18 +0800
Subject: [PATCH] fix:立行立改责任主体修改提交
---
screen-common/src/main/java/com/moral/util/AESUtils.java | 26 +++++++++++++++++++-------
1 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/screen-common/src/main/java/com/moral/util/AESUtils.java b/screen-common/src/main/java/com/moral/util/AESUtils.java
index ef66d11..59ecd74 100644
--- a/screen-common/src/main/java/com/moral/util/AESUtils.java
+++ b/screen-common/src/main/java/com/moral/util/AESUtils.java
@@ -6,6 +6,8 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.net.util.Base64;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
/**
* @ClassName AESUtil
@@ -15,9 +17,10 @@
* @Version TODO
**/
@Slf4j
+@Component
public class AESUtils {
//������
- public static String key = "AD42F7787B035B7580000EF93BE20BAD";
+ public static String key ;
//���������
private static String charset = "utf-8";
// ���������
@@ -25,6 +28,14 @@
//AES������
private static String transformation = "AES/CBC/PKCS5Padding";
private static String algorithm = "AES";
+
+
+ @Value("${AES.KEY}")
+ public void setKey(String key) {
+ AESUtils.key = key;
+ }
+
+
//������
public static String encrypt(String content) {
@@ -56,8 +67,8 @@
//������
public static String decrypt(String content, String key) {
try {
- SecretKeySpec skey = new SecretKeySpec(key.getBytes(), algorithm);
- IvParameterSpec iv = new IvParameterSpec(key.getBytes(), 0, offset);
+ SecretKeySpec skey = new SecretKeySpec(key.getBytes("utf-8"), algorithm);
+ IvParameterSpec iv = new IvParameterSpec(key.getBytes("utf-8"), 0, offset);
Cipher cipher = Cipher.getInstance(transformation);
cipher.init(Cipher.DECRYPT_MODE, skey, iv);// ���������
byte[] result = cipher.doFinal(new Base64().decode(content));
@@ -70,10 +81,11 @@
}
public static void main(String[] args) {
- System.out.println(encrypt("123456").length());
- System.out.println(encrypt("chenkaiyu111").length());
- System.out.println(encrypt("ASDKJLFHDLSKJ").length());
- System.out.println(encrypt("chenkaiiiiiiiiiiiii").length());
+ // System.out.println(encrypt("123456","AD42F7787B035B7580000EF93BE20BAD"));
+ //123456 KoWjfDMZQhJMLlG1crBPqQ==
+ // ������������
+ String str = decrypt("KoWjfDMZQhJMLlG1crBPqQ==", "AD42F7787B035B7580000EF93BE20BAD");
+ System.out.println(str);
}
}
--
Gitblit v1.8.0