package com.jiayue.ssi.service;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.util.CharsetUtil;
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.util.Map;

/**
* test
*
* @author xsl
* @since 2023/02/22
*/
public class Test {
    public static void main(String[] args) throws Exception{
//        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);
//



//        String hex = "757365726E616D653D61646D696E2670617373776F72643D61646D696E26636F64653D3963356226766572696679757569643D6534336331633731626266643464313861306439353236633636663131363630266D61696C626F783D313131313131";
//        int bsLength = hex.length();
//        if (bsLength % 2 != 0) {
//            hex = "0"+hex;
//            bsLength = hex.length();
//        }
//        byte[] cs = new byte[bsLength / 2];
//        String st;
//        for (int i = 0; i < bsLength; i = i + 2) {
//            st = hex.substring(i, i + 2);
//            cs[i / 2] = (byte) Integer.parseInt(st, 16);
//        }
////        System.out.println(new String(cs,"utf-8"));
//        String content = "SM2签名和验签";
//        final SM2 sm2 = SmUtil.sm2("27ce6eec39dbf3b564a77c4da1e129fe1ba01a92f6d61055a33ed14ffcbc949e","0460ff8c8c306fe62f6f9d11c5c82c30d10bbbc703da094e423072cac7dc663c97fad52eccb34f311f47a07f280de157ba4f2aa659cabe749121384b9376ea2ed2");
//        String sign = sm2.signHex(HexUtil.encodeHexStr(content));
//        System.out.println("sign:" + sign);
//
//        boolean verify = sm2.verifyHex(HexUtil.encodeHexStr(content), sign);
//        System.out.println("校验结果为：" + verify);

//        String str = "{\"username\":\"admin\",\"password\":\"1234565\"}";
//        Map<String,Object> map = JSONUtil.parseObj(str).getRaw();
//        System.out.println(map.get("username"));
//        System.out.println(map.get("password"));
// 66c7f0f462eeedd9d1f2d46bdc10e4e24167c4875cf2f7a2297da02b8f4ba8e0
// 66c7f0f462eeedd9d1f2d46bdc10e4e24167c4875cf2f7a2297da02b8f4ba8e0
        System.out.println(SmUtil.sm3("abc"));
//
//
//        System.out.println(Convert.toDBC("Xsl147258"));


    }
}
