# 导入SM2加密密钥对

导入SM2加密密钥对

# 一、请求说明

  • 请求地址:https://IP:PORT/openapi/ces/v1/keypair/import-sm2-encryption
  • 服务接口名称(即公共参数method的值): keypair/import-sm2-encryption
  • 请求方式:POST

# 二、请求参数

名称 类型 是否必须 描述
virtualIndex Integer 虚拟索引
encPrivateKey String 加密私钥 base64
encPublicKey String 加密公钥 base64
protectiveStructure Integer 加密私钥保护结构类型(不填为无保护结构)
  • 字段解释
  • protectiveStructure 加密私钥保护结构类型说明
传入值 结构类型
0 无保护结构
1 SM2CIPHER sm2保护结构
2 SM4CIPHER sm4保护结构

# 三、响应参数

名称 类型 描述
encPublicKey String 加密密钥对公钥

# 四、成功示例

JSON示例

{
    "code": 0,
    "message": "success",
    "requestId":"xxx",
}

# 五、失败示例

JSON示例

{
    "code": 10010,
    "requestId":"xxx",
    "message": "参数错误",
}

# 六、SDK请求示例

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

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

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

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

        KeypairImportSm2Request request = new KeypairImportSm2Request();
		
		Integer virtualIndex = 20023;

        String encPrivateKey = "bs4PSVKe0****/ZEPuHnG2h4u6z7nfUUsVQAs=";

        String encPublicKey = "BKH4KjNJRpHO3mL7***qQbpYZRS+2MTf1Pru+cYC2psQrxetxAo=";

		
		// 虚拟索引
		request.setVirtualIndex(virtualIndex);
		
		// 加密私钥base64
		request.setEncPrivateKey(encPrivateKey);
		
		// 加密公钥base64
		request.setEncPublicKey(encPublicKey);
		
        try {
            KeypairImportSm2Response response = client.execute(request);
            // 后续业务
            if (response.isSuccess()) {
                System.out.println("成功:" + response.getResult());
                KeypairImportSm2Response.Result result = response.getResult();
                System.out.println("加密密钥对公钥: " + result.getEncPublicKey());
            } else {
                System.out.println("失败:" + response.getBody());
            }
        } catch (ApiException e) {
            e.printStackTrace();
        }
最后更新于: 2/1/2023, 4:54:28 PM