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