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 +++++++++++++++++++++++++++++++++ 说明.txt | 5 +++++ se-modules/se-system/src/main/java/com/se/system/controller/SysSoftController.java | 17 +++++++++++++++-- 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/se-modules/se-system/src/main/java/com/se/system/controller/SysSoftController.java b/se-modules/se-system/src/main/java/com/se/system/controller/SysSoftController.java index cefa489..6ff6952 100644 --- a/se-modules/se-system/src/main/java/com/se/system/controller/SysSoftController.java +++ b/se-modules/se-system/src/main/java/com/se/system/controller/SysSoftController.java @@ -9,6 +9,7 @@ import com.se.system.domain.vo.NacosConfigVo; import com.se.system.service.NacosService; import com.se.system.service.inte.IAServerInfoService; +import com.se.system.utils.CommonUtils; import org.springframework.web.bind.annotation.*; import com.se.common.log.annotation.Log; import com.se.common.log.enums.BusinessType; @@ -128,11 +129,23 @@ } } - @GetMapping(value = "/test") - public AjaxResult test() { + @GetMapping(value = "/getServerInfo") + public AjaxResult getServerInfo() { LicenseExtraParamVo serverInfos = IAServerInfoService.getServer("").getServerInfos(); System.out.println("serverInfos = " + serverInfos); return success(serverInfos); } + + @GetMapping(value = "/getLicenseKey") + public AjaxResult getLicenseKey() throws Exception { + LicenseExtraParamVo serverInfos = IAServerInfoService.getServer("").getServerInfos(); + String jsonString = serverInfos.toJsonString(); + + System.out.println("鍘熷鏁版嵁 = " + jsonString); + String encryptedJson = CommonUtils.encrypt(jsonString); + System.out.println("鍔犲瘑鏁版嵁 = " + serverInfos); + + return success(encryptedJson); + } } 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)); diff --git "a/\350\257\264\346\230\216.txt" "b/\350\257\264\346\230\216.txt" index b9ab9b1..8b46459 100644 --- "a/\350\257\264\346\230\216.txt" +++ "b/\350\257\264\346\230\216.txt" @@ -102,4 +102,9 @@ docker run --net=mynetwork --ip=192.168.0.100 -d nginx docker run --mac-address=02:42:ac:11:00:02 -d nginx +鍘熷鏁版嵁 = {"ipAddress": ["192.168.11.73"], "macAddress": ["E0-70-EA-AA-B6-43"], "cpuSerial": "BFEBFBFF000806D1", "mainBoardSerial": "PLKEU018JFR3UK", "registerAmount": "null"} +鍔犲瘑鍚� = 7FVYWGz0OaLAi4QUekBejYTR0YUjfbyN1qJskbkIav0QVZUL92q1GAwSJsjXA8cIRrgsxhWkAmLtDQIUiRUC3geB7ydigxsc6kUOowT5jtfDr8c1hicyr0JmxKMFcWB3t9ciQ25A4Oz4UK7n5/BjJHKVWgsa9VON28By47JDL8VN17jSpUIIukjAj9Gm22iLGSgIj+9yC0mOaS5rtbRivo3Vh1Zy+HxyxntWPWRodBk= +瑙e瘑鍚� = {"ipAddress": ["192.168.11.73"], "macAddress": ["E0-70-EA-AA-B6-43"], "cpuSerial": "BFEBFBFF000806D1", "mainBoardSerial": "PLKEU018JFR3UK", "registerAmount": "null"} + +java license-creator-1.0.jar -k 7FVYWGz0OaLAi4QUekBejYTR0YUjfbyN1qJskbkIav0QVZUL92q1GAwSJsjXA8cIRrgsxhWkAmLtDQIUiRUC3geB7ydigxsc6kUOowT5jtfDr8c1hicyr0JmxKMFcWB3t9ciQ25A4Oz4UK7n5/BjJHKVWgsa9VON28By47JDL8VN17jSpUIIukjAj9Gm22iLGSgIj+9yC0mOaS5rtbRivo3Vh1Zy+HxyxntWPWRodBk= -i "2025-01-01 00:00:00" -e "2026-01-01 00:00:00" -------------------------------------------------------- 闃块噷-閫氫箟鐏电爜 -- Gitblit v1.9.3