package com.inspect.base.core.utils;

import cn.hutool.crypto.asymmetric.SM2;

public class Sm2Tools {
    public static final String privateKeyHex = "AD97C804E1F067261D552CD43E46B3C084496EBDB6AE53A58A17411E59A41597";
    public static final String x = "9A91A9DD01B0505CC0F008228FDA15A6F226E4AAE089ACA5FEFE204F9184A702";
    public static final String y = "66E47548E8AB6F5FD8F6EA407C4E7869E4476CB1E1778DB5D37E99C45E67CA6C";
    public static final String id = "31323334353637383132333435363738";
    public static final SM2 sm2 = new SM2("AD97C804E1F067261D552CD43E46B3C084496EBDB6AE53A58A17411E59A41597", "9A91A9DD01B0505CC0F008228FDA15A6F226E4AAE089ACA5FEFE204F9184A702", "66E47548E8AB6F5FD8F6EA407C4E7869E4476CB1E1778DB5D37E99C45E67CA6C");

    public static void main(String[] args) {
        String data = "1";
        String sign = sign(data);
        System.out.println("签名结果：" + sign);
        boolean verify = verify(data, sign);
        System.out.println("验签结果：" + verify);
    }

    public static String sign(String data) {
        return sm2.signHex(data, "31323334353637383132333435363738");
    }

    public static boolean verify(String data, String sign) {
        return sm2.verifyHex(data, sign);
    }

    static {
        sm2.usePlainEncoding();
    }
}
