package com.jiayue.ssi.service;

import cn.hutool.crypto.SmUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson2.JSON;
import com.jiayue.ssi.constant.SecretKeyConstants;
import com.jiayue.ssi.util.SM2CryptUtils;

/**
* 解析返回前端的加密数据
*
* @author xsl
* @since 2023/03/14
*/
public class Sm2UiTest {
    public static void main(String[] args) {
//        // 返回前端的加密数据
//        String encrypt = "b249d7a7c5322dc66cce4cad025cd451182b841dff6ca4a35dc52c1a2145de3725ebf0aed4829d731c536d7de819a52e392748492ec86571696a621df0eabe5510fea6327f5b3da61573e9ff103c1765e234046371d8972a6547478d27219b94ecaef8ce2bfb28b9c9db5a3d64b706cf73fac1d6bde60f7d3ecd2ab2353a18d383ed85e4ad4e8a1ac27c607d12d411e69e294d8c89d7327c983566920ede54bc827b83e9f6e7514d0e9619cdddcc6b42f6a6dc608e74285a6e42";
//        // 返回前端签名数据
//        String signStr = "3046022100cabcfdfbe9969122c3748dec9e3bf0b277e1a7065a57c6654ea23694813f1c79022100da8611cc8928cdd9abb9094888c50a482918bb28aea509e0785c90b95899c9cf";
//        String text = SM2CryptUtils.decrypt(encrypt, SecretKeyConstants.CLIENT_PRIVATE_KEY);
//            System.out.println("解密："+text);
//            boolean bo = SM2CryptUtils.verifySign(SecretKeyConstants.SERVER_PUBLIC_KEY,text,signStr);
//            System.out.println("验签："+bo);




//        String jiami = SM2CryptUtils.encrypt("root","041967638ca43d4577d8dba166bff4437fde944270101f398a95b846ec2f8177d09f8abc5d62b6cd2c7216274d7abe0c8e04b0bb691207a32dd2e12d6bd2798672");
//        System.out.println("加密："+jiami);
        String jiemi = SM2CryptUtils.decrypt("859605db44ad8ddb4ea74241ed051917ec11b62380d59e1fa879bd4febc47eabdd15812c4f46a8bfb0614f5165e068a9e2adac11e79a52929812305c29fade8bcaee16312b14d30e12339dd9d23142eccbaa704072f64f3bd26601ca2acd374182a3ee7a6f60a7bfbefc7b0e6c7ef4ef71ad0bb39c5651d2a010aabc314cfef96116f0f578d409188d571d4e2d920ebd908a0fb7c817d6dfcc4f77aef03aa4c6e1f912db444e12e967205ddb5ef99b5f80857dda4ea43de430bd38c74d5c10afc0d602294c01e2a3f5155239b7c23a8f4d62f2580f4a28c77f9f80f851fb23aa3310f523aed5a435063be4eabf91dbd42a1ed186f1583a",SecretKeyConstants.CLIENT_PRIVATE_KEY);
        System.out.println("解密："+jiemi);
        Object sysTime = JSONUtil.parseObj(JSONUtil.parseObj(jiemi).get("data")).get("sysTime");
        Object lk = JSONUtil.parseObj(JSONUtil.parseObj(jiemi).get("data")).get("lk");

        String jiemi1 = SM2CryptUtils.decrypt("076a067abdb37b6aa48ec8aa16df410cd570be34d7c2f316331e82e0afb866a4cd730407f5c71e2e9615325a316fb7a7856295d6b6a21d697314f16b023d0665816886491ab6e290b5c4be1b1f87af0cc52fd59f5705983b39fee1497d5ff89e1ab6875317bfcee70700f600aa744b22289891db3e73a1e8fd0494eb8e543d05091179292c09626c51e9272b7af41400bdcc83006bf7d8413524eaaed8486ca50ba450822cfce490dbedba9a0b66386cb722d7257ea3df470b9b50b88e",SecretKeyConstants.SERVER_PRIVATE_KEY);
        System.out.println("解密："+jiemi1);

        String commitStr = JSONUtil.parseObj(jiemi1).put("sysTime",sysTime).put("lk",lk).toString();

        String qdjiami = SM2CryptUtils.encrypt(commitStr,SecretKeyConstants.SERVER_PUBLIC_KEY);
        System.out.println("前端加密："+qdjiami);
        String qdqianming = SM2CryptUtils.sign(SecretKeyConstants.CLIENT_PRIVATE_KEY,commitStr);
        System.out.println("前端签名："+qdqianming);
//
//
//        String qianming = SM2CryptUtils.sign("6155d63ee27cbeca07f3e40c4f8856f1be8119fcbda1aadc7e0e595e52bad7bd",jiemi);
//        System.out.println("签名："+qianming);
//
//        boolean yanqian = SM2CryptUtils.verifySign("041967638ca43d4577d8dba166bff4437fde944270101f398a95b846ec2f8177d09f8abc5d62b6cd2c7216274d7abe0c8e04b0bb691207a32dd2e12d6bd2798672",jiemi,qianming);
//        System.out.println("验签："+yanqian);


//        String a= SmUtil.sm3("Xsl147258").toUpperCase();
//        System.out.println(SM2CryptUtils.encrypt(a,SecretKeyConstants.SERVER_PUBLIC_KEY));


    }
}
