TRX 1 an în urmă
părinte
comite
3ee4a435b3

+ 13 - 2
PaymentServer/src/main/java/com/zhongshu/payment/server/core/utils/TestSM2.java

@@ -1,13 +1,18 @@
 package com.zhongshu.payment.server.core.utils;
 
 import cn.hutool.json.JSONObject;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.util.StopWatch;
 
 /**
  * @author TRX
  * @date 2024/9/2
  */
+@Slf4j
 public class TestSM2 {
     public static void main(String[] args) {
+        StopWatch stopwatch = new StopWatch();
+        stopwatch.start("1");
         String pwd = "123456";
         JSONObject jsonObject = new JSONObject();
         jsonObject.set("pwd", pwd);
@@ -15,7 +20,9 @@ public class TestSM2 {
         jsonObject.set("age", 18);
         jsonObject.set("mid", "10037e6f803bc8ab01805fd07db4000d");
         pwd = jsonObject.toString();
+        stopwatch.stop();
 
+        stopwatch.start("2");
         System.out.println("未加密密码:" + pwd);
         String[] sm2Keys = Sm2Util.getSm2Keys(false);
         String pubKey = sm2Keys[0];
@@ -23,7 +30,8 @@ public class TestSM2 {
         System.out.println("公钥base64:" + AesUtils.base64Encode(pubKey));
         String priKey = sm2Keys[1];
         System.out.println("私钥:" + priKey);
-
+        stopwatch.stop();
+        stopwatch.start("3");
         // 国密加密
         String encrypt = Sm2Util.encrypt(pubKey, pwd);
         System.out.println("国密加密后密码:" + encrypt);
@@ -31,11 +39,14 @@ public class TestSM2 {
         // 国密解密
         String decrypt = Sm2Util.decrypt(priKey, encrypt);
         System.out.println("国密解密后密码:" + decrypt);
-
+        stopwatch.stop();
+        stopwatch.start("4");
         // BC库加密
         String encrypt1 = Sm2Util.encrypt(pubKey, pwd, 1);
         System.out.println("BC加密:" + encrypt1);
         String decrypt1 = Sm2Util.decrypt(priKey, encrypt1, 1);
         System.out.println("BC解密:" + decrypt1);
+        stopwatch.stop();
+        log.info("{}", stopwatch.prettyPrint());
     }
 }