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

import cn.unitid.matrix.pkiservice.sdk.ces.response.KeypairExportPublicKeyResponse;
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.KeypairExportPublicKeyRequest;
import org.junit.Test;

/**
 * 密钥对服务--导出公钥
 */
public class KeypairExportPublicKeyTest {

    public static void main(String[] args) {

        // 提供的URL
        String url = "http://172.16.3.232:25115";

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

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

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

        KeypairExportPublicKeyRequest request = new KeypairExportPublicKeyRequest();

        Integer virtualIndex = 20021;

        // 虚拟索引
        request.setVirtualIndex(virtualIndex);

        try {
            KeypairExportPublicKeyResponse response = pkiClient.execute(request);
            // 后续业务
            if (response.isSuccess()) {
//                System.out.println("成功：" + response.getResult());
                KeypairExportPublicKeyResponse.Result result = response.getResult();

                System.out.println("密钥算法: " + result.getAlgorithm());
                System.out.println("密钥算法长度: " + result.getKeySize());
                System.out.println("签名公钥base64: " + result.getSignPublicKey());
                System.out.println("加密公钥base64: " + result.getEncPublicKey());
                // 加密引擎类型: FILE--文件,FM_CARD--加密卡
                System.out.println("加密引擎类型: " + result.getCryptogramEngineType());
            } else {
                System.out.println("失败：" + response.getBody());
            }
        } catch (ApiException e) {
            e.printStackTrace();
        }

    }
}
