|
@@ -1,72 +1,38 @@
|
|
|
package com.jiayue.ssi.service;
|
|
|
|
|
|
-import com.backcore.constant.WeightValue;
|
|
|
+import cn.hutool.core.date.DateUnit;
|
|
|
+import cn.hutool.core.util.HexUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.crypto.BCUtil;
|
|
|
+import cn.hutool.crypto.SmUtil;
|
|
|
+import cn.hutool.crypto.asymmetric.KeyType;
|
|
|
+import cn.hutool.crypto.asymmetric.SM2;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.jiayue.ssi.constant.SecretKeyConstants;
|
|
|
+import com.jiayue.ssi.util.LocalCache;
|
|
|
+import com.jiayue.ssi.util.SM2CryptUtils;
|
|
|
+import org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey;
|
|
|
|
|
|
-import java.lang.reflect.Field;
|
|
|
-import java.lang.reflect.Method;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
- * TODO
|
|
|
- *
|
|
|
- * @author xsl
|
|
|
- * @version 3.0
|
|
|
- */
|
|
|
+* test
|
|
|
+*
|
|
|
+* @author xsl
|
|
|
+* @since 2023/02/22
|
|
|
+*/
|
|
|
public class Test {
|
|
|
public static void main(String[] args) throws Exception{
|
|
|
-// List<String> joList = new ArrayList<>();
|
|
|
-// for (int i=0;i<7;i++){
|
|
|
-// int j = 6-i;
|
|
|
-// joList.add(i+":"+j);
|
|
|
-// System.out.println(i+":"+j);
|
|
|
-// }
|
|
|
-// System.out.println("===============");
|
|
|
-// List<String> qjList = new ArrayList<>();
|
|
|
-// for (int i=0;i<=6;i++){
|
|
|
-// int j = 6 - i;
|
|
|
-// for (int k=0;k<=j;k++){
|
|
|
-// int m = j-k;
|
|
|
-// qjList.add(i+":"+k+":"+m);
|
|
|
-// System.out.println(i+":"+k+":"+m);
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// List<String> zhList = new ArrayList<>();
|
|
|
-// for (String joStr:joList){
|
|
|
-// for (String qjStr:qjList){
|
|
|
-// zhList.add(joStr+"-"+qjStr);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// System.out.println(zhList.size());
|
|
|
-
|
|
|
-// SsqData s1 = new SsqData();
|
|
|
-// s1.setIssue("030045");
|
|
|
-// SsqData s2 = new SsqData();
|
|
|
-// s2.setIssue("001730");
|
|
|
-//
|
|
|
-// List<SsqData> list = new ArrayList();
|
|
|
-// list.add(s1);
|
|
|
-// list.add(s2);
|
|
|
-// List<SsqData> list1 = list.stream().sorted(Comparator.comparing(SsqData::getIssue)).collect(Collectors.toList());
|
|
|
-//// list.stream().sorted(Comparator.comparing(SsqData::getIssue));
|
|
|
-// for (SsqData ssqData:list1){
|
|
|
-// System.out.println(ssqData.getIssue());
|
|
|
-// }
|
|
|
-// Float.parseFloat()
|
|
|
- WeightValue totalWeightValue = new WeightValue();
|
|
|
- totalWeightValue.setR5(10);
|
|
|
- totalWeightValue.setR1(5);
|
|
|
-
|
|
|
- Field[] field = totalWeightValue.getClass().getDeclaredFields();
|
|
|
- // 遍历所有属性
|
|
|
- for (int j = 0; j < field.length; j++) {
|
|
|
- // 获取属性的名字
|
|
|
- String name = field[j].getName();
|
|
|
- if ("r".equals(name.substring(0,1))){
|
|
|
- name = name.substring(0, 1).toUpperCase() + name.substring(1);
|
|
|
- Method m = totalWeightValue.getClass().getMethod("get" + name);
|
|
|
- System.out.println(name+"=>"+m.invoke(totalWeightValue));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+ SM2 sm2 = SmUtil.sm2();
|
|
|
+ //这里会自动生成对应的随机秘钥对
|
|
|
+ byte[] privateKey = BCUtil.encodeECPrivateKey(sm2.getPrivateKey());
|
|
|
+ //这里默认公钥压缩 公钥的第一个字节用于表示是否压缩 02或者03表示是压缩公钥,04表示未压缩公钥
|
|
|
+// byte[] publicKey = BCUtil.encodeECPublicKey(sm2.getPublicKey());
|
|
|
+ //这里得到未压缩的公钥
|
|
|
+ byte[] publicKey = ((BCECPublicKey) sm2.getPublicKey()).getQ().getEncoded(false);
|
|
|
+ String priKey = HexUtil.encodeHexStr(privateKey);
|
|
|
+ String pubKey = HexUtil.encodeHexStr(publicKey);
|
|
|
+ System.out.println(priKey);
|
|
|
+ System.out.println(pubKey);
|
|
|
}
|
|
|
}
|