package cn.unitid.matrix.pkiservice.test.svs;

import cn.unitid.matrix.pkiservice.sdk.ApiException;
import cn.unitid.matrix.pkiservice.sdk.PkiClient;
import cn.unitid.matrix.pkiservice.sdk.PkiOkhttpClient;
import cn.unitid.matrix.pkiservice.sdk.consts.DataType;
import cn.unitid.matrix.pkiservice.sdk.svs.request.P7VerifyRequest;
import cn.unitid.matrix.pkiservice.sdk.svs.response.P7VerifyResponse;

/**
 * 作者： 徐霁
 * <p>
 * 时间： 2021/5/24 10:18
 * <p>
 * 描述信息： P7q签名验证
 */
public class P7VerifyASN1Test {

    public static void main(String[] args) {

        // 提供的URL
        String url = "http://172.16.6.76:9200";

        // 您的appKey
        String appKey = "MJiAMOiLcL";

        // 您的appSecret
        String appSecret = "iS3O3EegecIMYGWQ7fkzx7sVElbeFGnh";

        // 1.原客户端
        PkiClient pkiClient = new PkiOkhttpClient(url, appKey, appSecret);

        String data = "MC8wCwYJYIZIAWUDBAIBBCAB13RlckLBHIdeiN20353jSVYH1eEXXJfd8/upNDEEtg==";

        String signature = "MIAGCSqGSIb3DQEHAqCAMIACAQExDzANBglghkgBZQMEAgEFADCABgkqhkiG9w0BBwEAAKCAMIICrTCCAZWgAwIBAgIEZAq9qTANBgkqhkiG9w0BAQsFADAYMQowCAYDVQQLDAEyMQowCAYDVQQDDAEyMB4XDTIzMDMxMDA1MTgzM1oXDTI0MDMwOTA1MTgzM1owGTEKMAgGA1UEAwwBMjELMAkGA1UEBhMCQ04wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCWCmuInjZj5cM2hkF4eylH51M8ZN1OLSO/6J6wCFl8lByB156bcyXZPrM9VSUHX1NpnausbAIvWH0koNBS69uIDP7r/JTIYJhJaiqfWefd1kKboyJBZN4NJDDv92TAqv2vd/ZWmZ3HDoQB5vUOVV/llAcpu33QvXM45MB0yxVQ+VhyFqk+zz6veVnsViIoojfK7tC8lLlRBTxlhZZq/IXZVT7tVFaL+6j67hHF5fqsd/e1UCDjc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=";

        P7VerifyRequest request = new P7VerifyRequest();
        // 签名值
        request.setSignature(signature);
        // 待验签数据
        request.setData(data);
        //待验签数据格式
        request.setDataType(DataType.ASN1_BASE64);
        // 签名是否包含原文
        request.setAttach(false);
        // 是否返回证书
        request.setReturnCert(true);


        try {
            P7VerifyResponse response = pkiClient.execute(request);
            // 后续业务
            if (response.isSuccess()) {
                System.out.println("成功响应：" + response.getBody());
            } else {
                System.out.println("失败响应：" + response.getBody());
            }
        } catch (ApiException e) {
            e.printStackTrace();
        }

    }

}
