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

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.ces.request.DigitalEnvelopeUnpackingRequest;
import cn.unitid.matrix.pkiservice.sdk.ces.response.DigitalEnvelopeUnpackingResponse;
import cn.unitid.matrix.pkiservice.sdk.consts.CertSearchEnum;
import cn.unitid.matrix.pkiservice.sdk.consts.DataType;

/**
 * 数字信封--拆包
 */
public class DigitalEnvelopeUnpackingTest {

    public static void main(String[] args) {
        // 提供的URL
//        String url = "http://localhost:20401";
        String url = "http://172.16.6.76:20501";

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

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

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

        DigitalEnvelopeUnpackingRequest request = new DigitalEnvelopeUnpackingRequest();

//        可选参数 非必填
//        // 通过何种方式进行拆包
//        request.setEncryptType(CertSearchEnum.CERT);
//        // 拆包项目的值
//        request.setEncryptItemValue("");

        // 数据格式
        request.setDataType(DataType.BASE64);

        // 待拆包数据
        request.setData("MIAGCiqBHM9VBgEEAgOggDCAAgEAMYHrMIHoAgEAMFowSTELMAkGA1UEBhMCQ04xEjAQBgNVBAgMCeaxn+iLj+ecgTESMBAGA1UEBwwJ5Y2X5Lqs5biCMRIwEAYDVQQDDAl0ZXN0U00yQ0ECDQDEuillc8CChwJ+ee4wCwYJKoEcz1UBgi0DBHoweAIgAZkBF/vjmXibCA77E3oqIsY09RgAfgua2MKKm224+RwCICDVQTJgC3hz7izCHUFt2a5Y0oO6TC4XIlUYN/Vz7bSbBCBGfiRRfqlHo8xmPePtePRQ7U5wOorcOt47+bB6GMmARwQQcBzFzEor97cTEp0ucUizyTCABgoqgRzPVQYBBAIBMBwGCCqBHM9VAWgCBBAMYBSOZwq3L1jKf6wjHD0+oIAEEHjJVGJGTM3dNhz4/dXhQbAAAAAAAAAAAAAA");

        request.setUnpackingDataType(DataType.ORIGINAL);

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


    }

}
