Ver Fonte

登录验证修改成SM4

ZhuDeKang há 2 meses atrás
pai
commit
1e31b8eb54

+ 41 - 20
ruoyi-common/src/main/java/com/ruoyi/common/utils/SM2EnhancedUtil.java

@@ -1,3 +1,4 @@
+/*
 package com.ruoyi.common.utils;
 
 import org.springframework.beans.factory.annotation.Value;
@@ -8,9 +9,11 @@ import java.security.KeyPair;
 import java.security.PrivateKey;
 import java.security.PublicKey;
 
+*/
 /**
  * 增强版SM2工具类
- */
+ *//*
+
 @Component
 public class SM2EnhancedUtil {
 
@@ -44,67 +47,85 @@ public class SM2EnhancedUtil {
         }
     }
 
-    /**
+    */
+/**
      * 使用配置的私钥签名
-     */
+     *//*
+
     public String sign(String data) {
         return SM2Util.sign(data.getBytes(), privateKey);
     }
 
-    /**
+    */
+/**
      * 使用配置的公钥验签
-     */
+     *//*
+
     public boolean verify(String data, String signature) {
         return SM2Util.verify(data.getBytes(), signature, publicKey);
     }
 
-    /**
+    */
+/**
      * 使用配置的私钥签名(字节数组)
-     */
+     *//*
+
     public String sign(byte[] data) {
         return SM2Util.sign(data, privateKey);
     }
 
-    /**
+    */
+/**
      * 使用配置的公钥验签(字节数组)
-     */
+     *//*
+
     public boolean verify(byte[] data, String signature) {
         return SM2Util.verify(data, signature, publicKey);
     }
 
-    /**
+    */
+/**
      * 获取当前使用的私钥(Base64)
-     */
+     *//*
+
     public String getPrivateKeyBase64() {
         return SM2Util.privateKeyToString(privateKey);
     }
 
-    /**
+    */
+/**
      * 获取当前使用的公钥(Base64)
-     */
+     *//*
+
     public String getPublicKeyBase64() {
         return SM2Util.publicKeyToString(publicKey);
     }
 
-    /**
+    */
+/**
      * 获取密钥对
-     */
+     *//*
+
     public KeyPair getKeyPair() {
         return keyPair;
     }
 
-    /**
+    */
+/**
      * 生成新的密钥对并更新当前实例
-     */
+     *//*
+
     public void generateNewKeyPair() {
         this.keyPair = SM2Util.generateKeyPair();
         this.privateKey = keyPair.getPrivate();
         this.publicKey = keyPair.getPublic();
     }
 
-    /**
+    */
+/**
      * 验证工具类是否正常工作
-     */
+     *//*
+
     public boolean selfCheck() {
         try {
             String testData = "SM2签名测试数据";
@@ -114,4 +135,4 @@ public class SM2EnhancedUtil {
             return false;
         }
     }
-}
+}*/

+ 34 - 16
ruoyi-common/src/main/java/com/ruoyi/common/utils/SM2Util.java

@@ -1,3 +1,4 @@
+/*
 package com.ruoyi.common.utils;
 
 import org.bouncycastle.jce.provider.BouncyCastleProvider;
@@ -8,9 +9,11 @@ import java.security.spec.PKCS8EncodedKeySpec;
 import java.security.spec.X509EncodedKeySpec;
 import java.util.Base64;
 
+*/
 /**
  * SM2非对称加密工具类 - 兼容版本
- */
+ *//*
+
 @Component
 public class SM2Util {
 
@@ -18,9 +21,11 @@ public class SM2Util {
         Security.addProvider(new BouncyCastleProvider());
     }
 
-    /**
+    */
+/**
      * 生成SM2密钥对
-     */
+     *//*
+
     public static KeyPair generateKeyPair() {
         try {
             // 使用标准的KeyPairGenerator
@@ -35,9 +40,11 @@ public class SM2Util {
         }
     }
 
-    /**
+    */
+/**
      * 使用私钥对数据进行签名
-     */
+     *//*
+
     public static String sign(byte[] data, PrivateKey privateKey) {
         try {
             Signature signature = Signature.getInstance("SM3withSM2", "BC");
@@ -50,9 +57,11 @@ public class SM2Util {
         }
     }
 
-    /**
+    */
+/**
      * 使用公钥验证签名
-     */
+     *//*
+
     public static boolean verify(byte[] data, String signature, PublicKey publicKey) {
         try {
             Signature verifier = Signature.getInstance("SM3withSM2", "BC");
@@ -65,9 +74,11 @@ public class SM2Util {
         }
     }
 
-    /**
+    */
+/**
      * 从Base64字符串加载私钥
-     */
+     *//*
+
     public static PrivateKey loadPrivateKey(String base64PrivateKey) {
         try {
             byte[] keyBytes = Base64.getDecoder().decode(base64PrivateKey);
@@ -75,13 +86,16 @@ public class SM2Util {
             KeyFactory keyFactory = KeyFactory.getInstance("EC", "BC");
             return keyFactory.generatePrivate(keySpec);
         } catch (Exception e) {
+            System.out.println(ExceptionUtil.getRootErrorMessage(e));
             throw new RuntimeException("加载SM2私钥失败", e);
         }
     }
 
-    /**
+    */
+/**
      * 从Base64字符串加载公钥
-     */
+     *//*
+
     public static PublicKey loadPublicKey(String base64PublicKey) {
         try {
             byte[] keyBytes = Base64.getDecoder().decode(base64PublicKey);
@@ -93,17 +107,21 @@ public class SM2Util {
         }
     }
 
-    /**
+    */
+/**
      * 将私钥转换为Base64字符串
-     */
+     *//*
+
     public static String privateKeyToString(PrivateKey privateKey) {
         return Base64.getEncoder().encodeToString(privateKey.getEncoded());
     }
 
-    /**
+    */
+/**
      * 将公钥转换为Base64字符串
-     */
+     *//*
+
     public static String publicKeyToString(PublicKey publicKey) {
         return Base64.getEncoder().encodeToString(publicKey.getEncoded());
     }
-}
+}*/