密码设备API接口文档

密码基础标准操作

一、公共参数

名称 类型 是否必须 描述
urlMap Map 是 中台服务地址集合,用于连接中台服务
location String 否 优先地域标识,用于根据地域标识优先选择中台服务
reserveLocation Map 否 备用地域标识集合,用于当其余地域的中台服务都不可用时,选择备用地域的中泰服务
appKey String 是 用户在业务系统中的标识,由业务系统提供
secretKey String 是 appKey对应的口令,用于校验用户的身份

使用内部SM2私钥对数据进行签名运算

签名。

一、请求说明

二、请求参数(请求方式为 post)

名称 类型 是否必须 描述
cipIndex Integer 是 密码中台密钥对虚拟索引
signData byte[] 是 待签名数据-提前将数据进行SM3摘要(必须为32字节长度的SM3摘要值)

代码实例

public class CipSopApiTest {

/**
* 使用内部SM2私钥对数据进行签名运算
*/
@Test
public void SDF_InternalSign_ECC() throws Exception {
// 提供的服务地址map集合
HashMap<String, String> map = new HashMap<String, String>();
map.put("cip.api.gf.demo.smartcert.cn", "cn-beijing-1");
map.put("cip.api.gx.demo.smartcert.cn","cn-nanjing-1");
// 优先地域
String location = "cn-nanjing";
// 备用地域集合
List<String> reserveLocation = new ArrayList<String>();
reserveLocation.add("cn-beijing");
// 您的appKey
String appKey = "w8MuGC9C";
// 您的secretKey
String secretKey = "4wVznIMB";
// 构造接口实例
ApiClient apiClient = new DefaultApiClient(map, location, reserveLocation, appKey, secretKey);
CipSopApi cipSopApi = new CipSopApiImpl(apiClient);

//签名请求数据
ApiByteCipSignSm2Request signSm2Request = new ApiByteCipSignSm2Request();
//基于密码中台的虚拟索引
signSm2Request.setCipIndex(1);
//提前将数据进行SM3摘要
EPMessageDigest messageDigest = EPMessageDigest.getInstance(EPAlgorithmIdentifier.SM3_ALGORITHM_OID);
byte[] digest = messageDigest.digest("待签名数据".getBytes());
//signData数据 必须为32字节长度的SM3摘要值
signSm2Request.setSignData(digest);
//签名服务
ApiByteCipSignSm2Response signSm2Response = cipSopApi.SDF_InternalSign_ECC(signSm2Request);
//后续业务处理
System.out.println("================================");
System.out.println("响应内容:" + signSm2Response);
System.out.println("================================");
System.out.println("SDK请求ID:" + signSm2Response.getRequestId());
System.out.println("SDK响应消息:" + signSm2Response.getMsg());
System.out.println("SDK响应码:" + signSm2Response.getErrorCode());
System.out.println("================================");
if (null != signSm2Response.getData()) {
System.out.println("签名结果数组:" + signSm2Response.getData().getSignedData());
System.out.println("签名结果字符串:" + signSm2Response.getData().getSignedDataHexStr());
System.out.println("密钥对所属的物理密码机ip地址:" + signSm2Response.getData().getIpAddress());
System.out.println("密钥对所属的物理密码机索引:" + signSm2Response.getData().getIndex());
System.out.println("密码中台密钥对虚拟索引:" + signSm2Response.getData().getCipIndex());
}
}
}

三、响应参数

字段名称 描述
errorCode 此次请求的结果 0-此次请求成功 其他-此次请求异常
msg 此次请求结果的描述,success-成功 其他-异常参见异常码
data 此次请求响应的负载,接口的响应信息主体
字段名称 描述
signedData 签名结果-byte数组
signedDataHexStr 签名结果-对签名结果数据经过Hex.encodeHexString后的字符串
ipAddress 密钥对所属的物理密码机ip地址
index 密钥对所属的物理密码机索引
cipIndex 密码中台密钥对虚拟索引

四、成功示例

JSON示例

{
"errorCode": 0,
"msg": "success",
"requestId": "f1486740f0a54ec08dc8adcac4e2af28",
"data": {
"signedData": byte[]...,
"signedDataHexStr": "...",
"ipAddress": "...",
"index": "...",
"cipIndex": "..."
},
"success": true
}

五、失败示例

JSON示例

{
"errorCode":14201,
"msg":"签名失败"
}

使用内部SM2公钥对签名值进行验签

将签名返回的数据进行验签(验证)。

一、请求说明

二、请求参数(请求方式为 post)

名称 类型 是否必须 描述
cipIndex Integer 是 密码中台密钥对虚拟索引
signData byte[] 是 待签名数据-提前将数据进行SM3摘要(必须为32字节长度的SM3摘要值)
signedData byte[] 是 签名结果数据-签名返回得byte数组

代码实例

public class CipSopApiTest {
/**
* 使用内部SM2公钥对签名值进行验签
*/
@Test
public void SDF_InternalVerify_ECC() throws Exception {
// 提供的服务地址map集合
HashMap<String, String> map = new HashMap<String, String>();
map.put("cip.api.gf.demo.smartcert.cn", "cn-beijing-1");
map.put("cip.api.gx.demo.smartcert.cn","cn-nanjing-1");
// 优先地域
String location = "cn-nanjing";
// 备用地域集合
List<String> reserveLocation = new ArrayList<String>();
reserveLocation.add("cn-beijing");
// 您的appKey
String appKey = "w8MuGC9C";
// 您的secretKey
String secretKey = "4wVznIMB";
// 构造接口实例
ApiClient apiClient = new DefaultApiClient(map, location, reserveLocation, appKey, secretKey);
CipSopApi cipSopApi = new CipSopApiImpl(apiClient);

//验签请求数据
ApiByteCipVerifySm2Request verifySm2Request = new ApiByteCipVerifySm2Request();
//提前将数据进行SM3摘要
EPMessageDigest messageDigest = EPMessageDigest.getInstance(EPAlgorithmIdentifier.SM3_ALGORITHM_OID);
byte[] digest = messageDigest.digest("待签名数据".getBytes());
//待签数据必须为32字节长度的SM3摘要值
verifySm2Request.setSignData(digest);
//基于密码中台的虚拟索引
verifySm2Request.setCipIndex(1);
//签名结果数据
verifySm2Request.setSignedData(Hex.decodeHex("3046022100d0c8bc55cc4447d13b322ae0e520d405b493de4bfdb09ed0a5847f2a80411b07022100a61ae537f356b2f973bf5c81b5f22beecce5e8b1ccd943589b70d2b6447bb4ca".toCharArray()));
//调用验签服务
ApiByteCipVerifySm2Response verifySm2Response = cipSopApi.SDF_InternalVerify_ECC(verifySm2Request);

//后续业务处理
System.out.println("================================");
System.out.println("响应内容:" + verifySm2Response);
System.out.println("================================");
System.out.println("SDK请求ID:" + verifySm2Response.getRequestId());
System.out.println("SDK响应消息:" + verifySm2Response.getMsg());
System.out.println("SDK响应码:" + verifySm2Response.getErrorCode());
System.out.println("================================");
if (null != verifySm2Response.getData()) {
System.out.println("验签结果:" + verifySm2Response.getData().getVerifyResult());
}
}
}

三、响应参数

字段名称 描述
errorCode 此次请求的结果 0-此次请求成功 其他-此次请求异常
msg 此次请求结果的描述,success-成功 其他-异常参见异常码
data 此次请求响应的负载,接口的响应信息主体
字段名称 描述
verifyResult 验签结果(true / false)

四、成功示例

JSON示例

{
"errorCode": 0,
"msg": "success",
"requestId": "2ab522460c5a434782dec0b75accbb6b",
"data": {
"verifyResult": true
},
"success": true
}

五、失败示例

JSON示例

{
"errorCode": 10000,
"msg": "验签失败"
}

sm2加密

api直接加密

一、请求说明

二、请求参数(请求方式为 post)

名称 类型 是否必须 描述
cipIndex Integer 是 密码中台密钥对虚拟索引
encryptData byte[] 是 待加密数据-byte[]-待加密机数据不能超过136个字节
keyUsageType KeyUsageType 否 进行加密时使用的密钥对类型-ENCRYPTION:加密密钥对;SIGNATURE:解密密钥对

代码实例

public class CipSopApiTest {

/**
* sm2加密
*/
@Test
public void SDF_EncryptWithPadding() throws Exception {
// 提供的服务地址map集合
HashMap<String, String> map = new HashMap<String, String>();
map.put("cip.api.gf.demo.smartcert.cn", "cn-beijing-1");
map.put("cip.api.gx.demo.smartcert.cn","cn-nanjing-1");
// 优先地域
String location = "cn-nanjing";
// 备用地域集合
List<String> reserveLocation = new ArrayList<String>();
reserveLocation.add("cn-beijing");
// 您的appKey
String appKey = "w8MuGC9C";
// 您的secretKey
String secretKey = "4wVznIMB";
// 构造接口实例
ApiClient apiClient = new DefaultApiClient(map, location, reserveLocation, appKey, secretKey);
CipSopApi cipSopApi = new CipSopApiImpl(apiClient);

//加密请求数据
ApiByteCipEncryptSm2Request encryptSm2Request = new ApiByteCipEncryptSm2Request();
//待加密数据 注意:待加密机数据不能超过136个字节
encryptSm2Request.setEncryptData("待加密数据".getBytes());
//基于密码中台的虚拟索引
encryptSm2Request.setCipIndex(1);
encryptSm2Request.setKeyUsageType(KeyUsageType.ENCRYPTION);
//调用加密服务
ApiByteCipEncryptSm2Response encryptSm2Response = cipSopApi.SDF_EncryptWithPadding(encryptSm2Request);

//后续业务处理
System.out.println("================================");
System.out.println("响应内容:" + encryptSm2Response);
System.out.println("================================");
System.out.println("SDK请求ID:" + encryptSm2Response.getRequestId());
System.out.println("SDK响应消息:" + encryptSm2Response.getMsg());
System.out.println("SDK响应码:" + encryptSm2Response.getErrorCode());
System.out.println("================================");
if (null != encryptSm2Response.getData()) {
System.out.println("加密结果-byte数组:" + encryptSm2Response.getData().getEncryptedData());
System.out.println("加密结果-HexStr字符串:" + encryptSm2Response.getData().getEncryptedDataHexStr());
System.out.println("密钥对所属的物理密码机ip地址:" + encryptSm2Response.getData().getIpAddress());
System.out.println("密钥对所属的物理密码机索引:" + encryptSm2Response.getData().getIndex());
System.out.println("密码中台密钥对虚拟索引:" + encryptSm2Response.getData().getCipIndex());
}
}
}

三、响应参数

字段名称 描述
errorCode 此次请求的结果 0-此次请求成功 其他-此次请求异常
msg 此次请求结果的描述,success-成功 其他-异常参见异常码
data 此次请求响应的负载,接口的响应信息主体
字段名称 描述
encryptedData 加密结果-byte数组
encryptedDataHexStr 加密结果字符串-对加密结果数据经过Hex.encodeHexString后的字符串
ipAddress 密钥对所属的物理密码机ip地址
index 密钥对所属的物理密码机索引
cipIndex 密码中台密钥对虚拟索引

四、成功示例

JSON示例

{
"errorCode": 0,
"msg": "success",
"requestId": "a0bddb76b98447408921e539ef4c5519",
"data": {
"encryptedData":byte[]...,
"encryptedDataHexStr":"...",
"ipAddress": "...",
"index": "...",
"cipIndex": "..."
},
"success":true

}

五、失败示例

JSON示例

{
"errorCode": 10000,
"msg": "加密失败"
}

sm2解密

对加密返回的数据进行解密

一、请求说明

二、请求参数(请求方式为 post)

名称 类型 是否必须 描述
cipIndex Integer 是 密码中台密钥对虚拟索引
decryptData byte[] 是 待解密数据-加密返回的byte数组
keyUsageType KeyUsageType 否 进行加密时使用的密钥对类型-ENCRYPTION:加密密钥对;SIGNATURE:解密密钥对

代码实例

public class CipSopApiTest  {

/**
* sm2解密
*/
@Test
public void SDF_DecryptWithUnpadding() {
// 提供的服务地址map集合
HashMap<String, String> map = new HashMap<String, String>();
map.put("cip.api.gf.demo.smartcert.cn", "cn-beijing-1");
map.put("cip.api.gx.demo.smartcert.cn","cn-nanjing-1");
// 优先地域
String location = "cn-nanjing";
// 备用地域集合
List<String> reserveLocation = new ArrayList<String>();
reserveLocation.add("cn-beijing");
// 您的appKey
String appKey = "w8MuGC9C";
// 您的secretKey
String secretKey = "4wVznIMB";
// 构造接口实例
ApiClient apiClient = new DefaultApiClient(map, location, reserveLocation, appKey, secretKey);
CipSopApi cipSopApi = new CipSopApiImpl(apiClient);

//解密请求数据
ApiByteCipDecryptSm2Request decryptSm2Request = new ApiByteCipDecryptSm2Request();
//待解密数据
decryptSm2Request.setDecryptData(Hex.decodeHex("30770220461bc4d572f5de4980a5e5d9b8a1ab486bad5ad40dc839cc0d2becfbea9ba2bf02202eade5a7a5d0cf995fade0eb9d7d017cc799ef899296912ffb273dbda8838f8b04204243d4de7c677908660c8ecec3828a53a076ae484766e36732a93ce1122db3eb040fd8e3514ca273c441b74c37367518de".toCharArray()));
//基于密码中台的虚拟索引
decryptSm2Request.setCipIndex(1);
decryptSm2Request.setKeyUsageType(KeyUsageType.ENCRYPTION);
//调用解密服务
ApiByteCipDecryptSm2Response decryptSm2Response = cipSopApi.SDF_DecryptWithUnpadding(decryptSm2Request);
//后续业务处理
System.out.println("================================");
System.out.println("响应内容:" + decryptSm2Response);
System.out.println("================================");
System.out.println("SDK请求ID:" + decryptSm2Response.getRequestId());
System.out.println("SDK响应消息:" + decryptSm2Response.getMsg());
System.out.println("SDK响应码:" + decryptSm2Response.getErrorCode());
System.out.println("================================");
if (null != decryptSm2Response.getData()) {
System.out.println("解密结果-byte数组:" + decryptSm2Response.getData().getDecryptedData());
System.out.println("解密结果-HexStr字符串:" + decryptSm2Response.getData().getDecryptedDataHexStr());
String s = new String(decryptSm2Response.getData().getDecryptedData());
System.out.println("解密结果-待加密数据:" + s);
}
}
}

三、响应参数

字段名称 描述
errorCode 此次请求的结果 0-此次请求成功 其他-此次请求异常
msg 此次请求结果的描述,success-成功 其他-异常参见异常码
data 此次请求响应的负载,接口的响应信息主体
字段名称 描述
decryptedData 解密结果-byte数组
decryptedDataHexStr 解密结果字符串-对解密结果数据经过Hex.encodeHexString后的字符串

四、成功示例

JSON示例

{
"errorCode": 0,
"msg": "success",
"requestId": "a0bddb76b98447408921e539ef4c5519",
"data": {
"decryptedData":byte[]...,
"decryptedDataHexStr":"..."
},
"success":true

}

五、失败示例

JSON示例

{
"errorCode": 10000,
"msg": "解密失败",
}

HMAC加密

api直接加密

一、请求说明

二、请求参数(请求方式为 post)

名称 类型 是否必须 描述
cipIndex Integer 是 密码中台密钥对虚拟索引
macData byte[] 是 待加密数据-byte[]
hmacAlgorithm HmacAlgorithmEnum 是 进行加密时使用的加密算法

代码实例

public class CipSopApiTest  {

/**
* HMAC加密
*/
@Test
public void HMAC_ALGORITHM() {
// 提供的服务地址map集合
HashMap<String, String> map = new HashMap<String, String>();
map.put("cip.api.gf.demo.smartcert.cn", "cn-beijing-1");
map.put("cip.api.gx.demo.smartcert.cn","cn-nanjing-1");
// 优先地域
String location = "cn-nanjing";
// 备用地域集合
List<String> reserveLocation = new ArrayList<String>();
reserveLocation.add("cn-beijing");
// 您的appKey
String appKey = "w8MuGC9C";
// 您的secretKey
String secretKey = "4wVznIMB";
// 构造接口实例
ApiClient apiClient = new DefaultApiClient(map, location, reserveLocation, appKey, secretKey);
CipSopApi cipSopApi = new CipSopApiImpl(apiClient);

//加密请求数据
ApiByteCipEncryptHMACAlgorithmRequest encryptSm2Request = new ApiByteCipEncryptHMACAlgorithmRequest();
//待加密数据
encryptSm2Request.setMacData("待加密数据".getBytes());
//基于密码中台的虚拟索引
encryptSm2Request.setCipIndex(cipIndex);
encryptSm2Request.setHmacAlgorithm(HmacAlgorithmEnum.HMAC_SM3);
//调用加密服务
ApiByteCipEncryptHMACAlgorithmResponse encryptSm2Response = cipSopApi.HMAC_ALGORITHM(encryptSm2Request);
//后续业务处理
System.out.println("================================");
System.out.println("响应内容:" + encryptSm2Response);
System.out.println("================================");
System.out.println("SDK请求ID:" + encryptSm2Response.getRequestId());
System.out.println("SDK响应消息:" + encryptSm2Response.getMsg());
System.out.println("SDK响应码:" + encryptSm2Response.getErrorCode());
System.out.println("================================");
if (null != encryptSm2Response.getData()) {
System.out.println("加密结果-byte数组:" + encryptSm2Response.getData().getDecryptedData());
System.out.println("加密结果-HexStr字符串:" + encryptSm2Response.getData().getGenMacDataHexStr());
System.out.println("密钥对所属的物理密码机ip地址:" + encryptSm2Response.getData().getIpAddress());
System.out.println("密钥对所属的物理密码机索引:" + encryptSm2Response.getData().getIndex());
System.out.println("密码中台密钥对虚拟索引:" + encryptSm2Response.getData().getCipIndex());
}
}
}

三、响应参数

字段名称 描述
errorCode 此次请求的结果 0-此次请求成功 其他-此次请求异常
msg 此次请求结果的描述,success-成功 其他-异常参见异常码
data 此次请求响应的负载,接口的响应信息主体
字段名称 描述
decryptedData 解密结果-byte数组
genMacDataHexStr 解密结果字符串-对解密结果数据经过Hex.encodeHexString后的字符串

四、成功示例

JSON示例

{
"errorCode": 0,
"msg": "success",
"requestId": "a0bddb76b98447408921e539ef4c5519",
"data": {
"decryptedData":byte[]...,
"genMacDataHexStr":"..."
},
"success":true

}

五、失败示例

JSON示例

{
"errorCode": 10000,
"msg": "加密失败",
}

申请随机数

申请随机数

一、请求说明

二、请求参数(请求方式为 post)

名称 类型 是否必须 描述
nLength Integer 否 随机数长度

代码实例

public class CipSopApiTest  {

/**
* 申请随机数
*/
@Test
public void randomTest() {
// 提供的服务地址map集合
HashMap<String, String> map = new HashMap<String, String>();
map.put("cip.api.gf.demo.smartcert.cn", "cn-beijing-1");
map.put("cip.api.gx.demo.smartcert.cn","cn-nanjing-1");
// 优先地域
String location = "cn-nanjing";
// 备用地域集合
List<String> reserveLocation = new ArrayList<String>();
reserveLocation.add("cn-beijing");
// 您的appKey
String appKey = "w8MuGC9C";
// 您的secretKey
String secretKey = "4wVznIMB";
// 构造接口实例
ApiClient apiClient = new DefaultApiClient(map, location, reserveLocation, appKey, secretKey);
CipSopApi cipSopApi = new CipSopApiImpl(apiClient);

//申请随机数
//随机数获取请求数据
RandomGenRequest randomGenRequest = new RandomGenRequest();
//随机数长度
randomGenRequest.setnLength(5000);
//随机数获取
RandomGenResponse response = cipSopApi.random(randomGenRequest);

//后续业务处理
System.out.println("================================");
System.out.println("响应内容:" + response);
System.out.println("================================");
System.out.println("SDK请求ID:" + response.getRequestId());
System.out.println("SDK响应消息:" + response.getMsg());
System.out.println("SDK响应码:" + response.getErrorCode());
System.out.println("================================");
if (null != response.getData()) {
System.out.println("随机数-byte数组:" + response.getData().getData());
System.out.println("随机数-HexStr字符串:" + response.getData().getDataHexStr());
}
}
}

三、响应参数

字段名称 描述
errorCode 此次请求的结果 0-此次请求成功 其他-此次请求异常
msg 此次请求结果的描述,success-成功 其他-异常参见异常码
data 此次请求响应的负载,接口的响应信息主体
字段名称 描述
data 随机数-byte数组
dataHexStr 随机数-byte数组的字符串

四、成功示例

JSON示例

{
"errorCode": 0,
"msg": "success",
"requestId": "a0bddb76b98447408921e539ef4c5519",
"data": {
"data":byte[]...,
"dataHexStr":"..."
},
"success":true

}

五、失败示例

JSON示例

{
"errorCode": 10000,
"msg": "获取随机数失败",
}

生成p10

生成p10

一、请求说明

二、请求参数(请求方式为 post)

名称 类型 是否必须 描述
subject String 是 证书主题信息
algorithm String 否 密钥算法-算法类型:SM2
cipIndex Integer 是 密码中台密钥对虚拟索引

代码实例

public class CipSopApiTest  {

/**
* 生成p10
*/
@Test
public void p10genTest() {
// 提供的服务地址map集合
HashMap<String, String> map = new HashMap<String, String>();
map.put("cip.api.gf.demo.smartcert.cn", "cn-beijing-1");
map.put("cip.api.gx.demo.smartcert.cn","cn-nanjing-1");
// 优先地域
String location = "cn-nanjing";
// 备用地域集合
List<String> reserveLocation = new ArrayList<String>();
reserveLocation.add("cn-beijing");
// 您的appKey
String appKey = "w8MuGC9C";
// 您的secretKey
String secretKey = "4wVznIMB";
// 构造接口实例
ApiClient apiClient = new DefaultApiClient(map, location, reserveLocation, appKey, secretKey);
CipSopApi cipSopApi = new CipSopApiImpl(apiClient);

//生成p10请求数据
P10GenRequest p10GenRequest = new P10GenRequest();
//证书主题信息
p10GenRequest.setSubject("CN=公司名,OU=壹证通,O=SmartCA,L=南京市,ST=江苏省,C=CN");
//基于密码中台的虚拟索引
p10GenRequest.setCipIndex(1);
//调用加密服务
P10GenResponse p10GenResponse = cipSopApi.p10gen(p10GenRequest);

//后续业务处理
System.out.println("================================");
System.out.println("响应内容:" + p10GenResponse);
System.out.println("================================");
System.out.println("SDK请求ID:" + p10GenResponse.getRequestId());
System.out.println("SDK响应消息:" + p10GenResponse.getMsg());
System.out.println("SDK响应码:" + p10GenResponse.getErrorCode());
System.out.println("================================");
if (null != p10GenResponse.getData()) {
System.out.println("p10:" + p10GenResponse.getData().getP10());
System.out.println("密钥对所属的物理密码机ip地址:" + p10GenResponse.getData().getIpAddress());
System.out.println("密钥对所属的物理密码机索引:" + p10GenResponse.getData().getIndex());
System.out.println("密码中台密钥对虚拟索引:" + p10GenResponse.getData().getCipIndex());
}
}
}

三、响应参数

字段名称 描述
errorCode 此次请求的结果 0-此次请求成功 其他-此次请求异常
msg 此次请求结果的描述,success-成功 其他-异常参见异常码
data 此次请求响应的负载,接口的响应信息主体
字段名称 描述
p10 base64的p10
ipAddress 密钥对所属的物理密码机ip地址
index 密钥对所属的物理密码机索引
cipIndex 密码中台密钥对虚拟索引

四、成功示例

JSON示例

{
"errorCode": 0,
"msg": "success",
"requestId": "a0bddb76b98447408921e539ef4c5519",
"data": {
"p10":"...",
"ipAddress":"...",
"index":"...",
"cipIndex":"..."
},
"success":true

}

五、失败示例

JSON示例

{
"errorCode": 10000,
"msg": "获取p10失败",
}

对称密钥加密

对称密钥加密

一、请求说明

二、请求参数(请求方式为 post)

名称 类型 是否必须 描述
data String 是 待加密数据
cipIndex Integer 是 基于密码中台的虚拟索引

代码实例

public class CipSopApiTest  {

/**
* 对称密钥加密
*/
@Test
public void symmetricEncrypt() {
// 提供的服务地址map集合
HashMap<String, String> map = new HashMap<String, String>();
map.put("cip.api.gf.demo.smartcert.cn", "cn-beijing-1");
map.put("cip.api.gx.demo.smartcert.cn","cn-nanjing-1");
// 优先地域
String location = "cn-nanjing";
// 备用地域集合
List<String> reserveLocation = new ArrayList<String>();
reserveLocation.add("cn-beijing");
// 您的appKey
String appKey = "w8MuGC9C";
// 您的secretKey
String secretKey = "4wVznIMB";
// 构造接口实例
ApiClient apiClient = new DefaultApiClient(map, location, reserveLocation, appKey, secretKey);
CipSopApi cipSopApi = new CipSopApiImpl(apiClient);

//对称密钥加密请求数据
SymmetricEncryptRequest symmetricEncryptRequest = new SymmetricEncryptRequest();
//基于密码中台的虚拟索引
symmetricEncryptRequest.setCipIndex(1);
symmetricEncryptRequest.setData("对称密钥待加密数据".getBytes());
//调用对称加密服务
SymmetricEncryptResponse symmetricEncryptResponse = cipSopApi.symmetricEncrypt(symmetricEncryptRequest);

//后续业务处理
System.out.println("================================");
System.out.println("响应内容:" + symmetricEncryptResponse);
System.out.println("================================");
System.out.println("SDK请求ID:" + symmetricEncryptResponse.getRequestId());
System.out.println("SDK响应消息:" + symmetricEncryptResponse.getMsg());
System.out.println("SDK响应码:" + symmetricEncryptResponse.getErrorCode());
System.out.println("================================");
if (null != symmetricEncryptResponse.getData()) {
System.out.println("加密后的数据-byte[]:" + symmetricEncryptResponse.getData().getEncryptedData());
System.out.println("加密后的数据字符串-HexStr字符串:" + symmetricEncryptResponse.getData().getDataHexStr());
System.out.println("密钥对所属的物理密码机ip地址:" + symmetricEncryptResponse.getData().getIpAddress());
System.out.println("密钥对所属的物理密码机索引:" + symmetricEncryptResponse.getData().getIndex());
System.out.println("密码中台密钥对虚拟索引:" + symmetricEncryptResponse.getData().getCipIndex());
}
}
}

三、响应参数

字段名称 描述
errorCode 此次请求的结果 0-此次请求成功 其他-此次请求异常
msg 此次请求结果的描述,success-成功 其他-异常参见异常码
data 此次请求响应的负载,接口的响应信息主体
字段名称 描述
encryptedData 加密后的数据-byte[]
dataHexStr 加密后的数据-对加密后的数据byte[]经过Hex.encodeHexString字符串
ipAddress 密钥对所属的物理密码机ip地址
index 密钥对所属的物理密码机索引
cipIndex 密码中台密钥对虚拟索引

四、成功示例

JSON示例

{
"errorCode": 0,
"msg": "success",
"requestId": "a0bddb76b98447408921e539ef4c5519",
"data": {
"encryptedData": byte[]...,
"dataHexStr": "...",
"ipAddress": "...",
"index": "...",
"cipIndex": "...",
},
"success":true

}

五、失败示例

JSON示例

{
"errorCode": 10000,
"msg": "对称密钥加密失败",
}

对称密钥解密

对称密钥解密

一、请求说明

二、请求参数(请求方式为 post)

名称 类型 是否必须 描述
data String 是 待加密数据
cipIndex Integer 是 基于密码中台的虚拟索引

代码实例

public class CipSopApiTest  {

/**
* 对称密钥解密
*/
@Test
public void symmetricDecrypt() {
// 提供的服务地址map集合
HashMap<String, String> map = new HashMap<String, String>();
map.put("cip.api.gf.demo.smartcert.cn", "cn-beijing-1");
map.put("cip.api.gx.demo.smartcert.cn","cn-nanjing-1");
// 优先地域
String location = "cn-nanjing";
// 备用地域集合
List<String> reserveLocation = new ArrayList<String>();
reserveLocation.add("cn-beijing");
// 您的appKey
String appKey = "w8MuGC9C";
// 您的secretKey
String secretKey = "4wVznIMB";
// 构造接口实例
ApiClient apiClient = new DefaultApiClient(map, location, reserveLocation, appKey, secretKey);
CipSopApi cipSopApi = new CipSopApiImpl(apiClient);
//对称密钥解密
SymmetricDecryptRequest symmetricDecryptRequest = new SymmetricDecryptRequest();
symmetricDecryptRequest.setData(Hex.decodeHex("b80338ec6fb26d568875ca54f2227ff217298ce097c08cef36324acbefe7e624".toCharArray()));
//基于密码中台的虚拟索引
symmetricDecryptRequest.setCipIndex(1);
//调用解密服务
SymmetricDecryptResponse symmetricDecryptResponse = cipSopApi.symmetricDecrypt(symmetricDecryptRequest);

//后续业务处理
System.out.println("================================");
System.out.println("响应内容:" + symmetricDecryptResponse);
System.out.println("================================");
System.out.println("SDK请求ID:" + symmetricDecryptResponse.getRequestId());
System.out.println("SDK响应消息:" + symmetricDecryptResponse.getMsg());
System.out.println("SDK响应码:" + symmetricDecryptResponse.getErrorCode());
System.out.println("================================");
if (null != symmetricDecryptResponse.getData()) {
System.out.println("解密后的数据-byte[]:" + symmetricDecryptResponse.getData().getDecryptedData());
System.out.println("解密结果-HexStr字符串:" + symmetricDecryptResponse.getData().getDecryptedDataHexStr());
System.out.println("密钥对所属的物理密码机ip地址:" + symmetricDecryptResponse.getData().getIpAddress());
System.out.println("密钥对所属的物理密码机索引:" + symmetricDecryptResponse.getData().getIndex());
System.out.println("密码中台密钥对虚拟索引:" + symmetricDecryptResponse.getData().getCipIndex());
String s = new String(symmetricDecryptResponse.getData().getDecryptedData());
System.out.println("解密结果-待加密数据:" + s);
}
}
}

三、响应参数

字段名称 描述
errorCode 此次请求的结果 0-此次请求成功 其他-此次请求异常
msg 此次请求结果的描述,success-成功 其他-异常参见异常码
data 此次请求响应的负载,接口的响应信息主体
字段名称 描述
decryptedData 解密后的数据-byte[]
decryptedDataHexStr 解密后的数据字符换-对解密后的数据经过Hex.encodeHexString后的字符串
ipAddress 密钥对所属的物理密码机ip地址
index 密钥对所属的物理密码机索引
cipIndex 密码中台密钥对虚拟索引

四、成功示例

JSON示例

{
"errorCode": 0,
"msg": "success",
"requestId": "a0bddb76b98447408921e539ef4c5519",
"data": {
"decryptedData": byte[]...,
"decryptedDataHexStr": "...",
"ipAddress": "...",
"index": "...",
"cipIndex": "...",
},
"success":true

}

五、失败示例

JSON示例

{
"errorCode": 10000,
"msg": "对称密钥解密失败",
}

申请指定索引的密钥对

申请指定索引的密钥对

一、请求说明

二、请求参数(请求方式为 post)

名称 类型 是否必须 描述
cipIndex Integer 否 基于密码中台的虚拟索引
repeat Boolean 是 申请密钥是否为对称密钥:对称密钥-true;非对称密钥-false

代码实例

public class CipSopApiTest  {

/**
* 申请索引的密钥对
*/
@Test
public void keyPairApply() {
// 提供的服务地址map集合
HashMap<String, String> map = new HashMap<String, String>();
map.put("cip.api.gf.demo.smartcert.cn", "cn-beijing-1");
map.put("cip.api.gx.demo.smartcert.cn","cn-nanjing-1");
// 优先地域
String location = "cn-nanjing";
// 备用地域集合
List<String> reserveLocation = new ArrayList<String>();
reserveLocation.add("cn-beijing");
// 您的appKey
String appKey = "w8MuGC9C";
// 您的secretKey
String secretKey = "4wVznIMB";
// 构造接口实例
ApiClient apiClient = new DefaultApiClient(map, location, reserveLocation, appKey, secretKey);
CipSopApi cipSopApi = new CipSopApiImpl(apiClient);

//请求数据
KeyPairApplyRequest applyRequest = new KeyPairApplyRequest();
applyRequest.setCipIndex(1);
applyRequest.setRepeat(false);
//申请虚拟索引
KeyPairApplyResponse keyPairApplyResponse = cipSopApi.keyPairApply(applyRequest);

//后续业务处理
System.out.println("================================");
System.out.println("响应内容:" + keyPairApplyResponse);
System.out.println("================================");
System.out.println("SDK请求ID:" + keyPairApplyResponse.getRequestId());
System.out.println("SDK响应消息:" + keyPairApplyResponse.getMsg());
System.out.println("SDK响应码:" + keyPairApplyResponse.getErrorCode());
System.out.println("================================");
if (null != keyPairApplyResponse.getData()) {
System.out.println("申请指定索引的密钥对响应结果:" + keyPairApplyResponse.getData().getApplyResult());
System.out.println("密码中台的虚拟索引:" + keyPairApplyResponse.getData().getCipIndex());
}
}
}

三、响应参数

字段名称 描述
errorCode 此次请求的结果 0-此次请求成功 其他-此次请求异常
msg 此次请求结果的描述,success-成功 其他-异常参见异常码
data 此次请求响应的负载,接口的响应信息主体
字段名称 描述
applyResult true / false
cipIndex 密码中台的虚拟索引

四、成功示例

JSON示例

{
"errorCode": 0,
"msg": "success",
"requestId": "a0bddb76b98447408921e539ef4c5519",
"data": {
"applyResult": ...,
"cipIndex": ...
},
"success":true

}

五、失败示例

JSON示例

{
"errorCode": 10000,
"msg": "申请指定索引的密钥对失败",
}

注销指定索引的密钥对

注销指定索引的密钥对

一、请求说明

二、请求参数(请求方式为 post)

名称 类型 是否必须 描述
cipIndex Integer 是 基于密码中台的虚拟索引

代码实例

public class CipSopApiTest  {

/**
* 注销指定索引的密钥对
*/
@Test
public void keyPairRecover() {
// 提供的服务地址map集合
HashMap<String, String> map = new HashMap<String, String>();
map.put("cip.api.gf.demo.smartcert.cn", "cn-beijing-1");
map.put("cip.api.gx.demo.smartcert.cn","cn-nanjing-1");
// 优先地域
String location = "cn-nanjing";
// 备用地域集合
List<String> reserveLocation = new ArrayList<String>();
reserveLocation.add("cn-beijing");
// 您的appKey
String appKey = "w8MuGC9C";
// 您的secretKey
String secretKey = "4wVznIMB";
// 构造接口实例
ApiClient apiClient = new DefaultApiClient(map, location, reserveLocation, appKey, secretKey);
CipSopApi cipSopApi = new CipSopApiImpl(apiClient);
//注销指定索引的密钥对请求数据
KeyPairRecoverRequest recoverRequest = new KeyPairRecoverRequest();
//基于密码中台的申请的虚拟索引
recoverRequest.setCipIndex(1);
//调用注销指定索引的密钥对
KeyPairRecoverResponse keyPairRecoverResponse = cipSopApi.keyPairRecover(recoverRequest);

//后续业务处理
System.out.println("================================");
System.out.println("响应内容:" + keyPairRecoverResponse);
System.out.println("================================");
System.out.println("SDK请求ID:" + keyPairRecoverResponse.getRequestId());
System.out.println("SDK响应消息:" + keyPairRecoverResponse.getMsg());
System.out.println("SDK响应码:" + keyPairRecoverResponse.getErrorCode());
System.out.println("================================");
if (null != keyPairRecoverResponse.getData()) {
System.out.println("注销指定索引的密钥对响应结果:" + keyPairRecoverResponse.getData().getRecoverResult());
System.out.println("注销指定索引的提示信息:" + keyPairRecoverResponse.getData().getMessage());
}
}
}

三、响应参数

字段名称 描述
errorCode 此次请求的结果 0-此次请求成功 其他-此次请求异常
msg 此次请求结果的描述,success-成功 其他-异常参见异常码
data 此次请求响应的负载,接口的响应信息主体
字段名称 描述
recoverResult true / false

四、成功示例

JSON示例

{
"errorCode": 0,
"msg": "success",
"requestId": "a0bddb76b98447408921e539ef4c5519",
"data": {
"recoverResult": ...,
"message": ...
},
"success":true
}

五、失败示例

JSON示例

{
"errorCode": 10000,
"msg": "注销指定索引的密钥对失败",
}

导出指定的SM2公钥

导出指定的SM2公钥

一、请求说明

二、请求参数(请求方式为 post)

名称 类型 是否必须 描述
cipIndex Integer 是 基于密码中台的虚拟索引
keyUsageType KeyUsageType-枚举 是 密钥用法类型-ENCRYPTION:加密密钥;SIGNATURE:签名密钥

代码实例

public class CipSopApiTest  {

/**
* 导出指定的SM2公钥
*/
@Test
public void sm2PubExport() {
// 提供的服务地址map集合
HashMap<String, String> map = new HashMap<String, String>();
map.put("cip.api.gf.demo.smartcert.cn", "cn-beijing-1");
map.put("cip.api.gx.demo.smartcert.cn","cn-nanjing-1");
// 优先地域
String location = "cn-nanjing";
// 备用地域集合
List<String> reserveLocation = new ArrayList<String>();
reserveLocation.add("cn-beijing");
// 您的appKey
String appKey = "w8MuGC9C";
// 您的secretKey
String secretKey = "4wVznIMB";
// 构造接口实例
ApiClient apiClient = new DefaultApiClient(map, location, reserveLocation, appKey, secretKey);
CipSopApi cipSopApi = new CipSopApiImpl(apiClient);

//导出指定的SM2公钥
//请求数据
Sm2PubExportRequest sm2PubExportRequest = new Sm2PubExportRequest();
sm2PubExportRequest.setCipIndex(1);
sm2PubExportRequest.setKeyUsageType(KeyUsageType.SIGNATURE);
Sm2PubExportResponse sm2PubExportResponse = cipSopApi.sm2PubExport(sm2PubExportRequest);
//后续业务处理
System.out.println("================================");
System.out.println("响应内容:" + sm2PubExportResponse);
System.out.println("================================");
System.out.println("SDK请求ID:" + sm2PubExportResponse.getRequestId());
System.out.println("SDK响应消息:" + sm2PubExportResponse.getMsg());
System.out.println("SDK响应码:" + sm2PubExportResponse.getErrorCode());
System.out.println("================================");
if (null != sm2PubExportResponse.getData()) {
System.out.println("公钥X坐标值-byte数组:" + sm2PubExportResponse.getData().getPubX());
System.out.println("公钥Y坐标值-byte数组:" + sm2PubExportResponse.getData().getPubY());
System.out.println("公钥X坐标值-HexStr字符串:" + sm2PubExportResponse.getData().getPubXHexStr());
System.out.println("公钥Y坐标值-HexStr字符串:" + sm2PubExportResponse.getData().getPubYHexStr());
}
}
}

三、响应参数

字段名称 描述
errorCode 此次请求的结果 0-此次请求成功 其他-此次请求异常
msg 此次请求结果的描述,success-成功 其他-异常参见异常码
data 此次请求响应的负载,接口的响应信息主体
字段名称 描述
pubX 公钥X坐标值-byte数组
pubY 公钥Y坐标值-byte数组
pubXHexStr 公钥X坐标值-HexStr字符串
pubYHexStr 公钥Y坐标值-HexStr字符串

四、成功示例

JSON示例

{
"errorCode": 0,
"msg": "success",
"requestId": "a0bddb76b98447408921e539ef4c5519",
"data": {
"pubX": ...,
"pubY": ...,
"pubXHexStr": ...,
"pubYHexStr": ...
},
"success":true
}

五、失败示例

JSON示例

{
"errorCode": 10000,
"msg": "导出指定的SM2公钥失败",
}

导入指定的SM2密钥对

SM2密钥对导入

一、请求说明

二、请求参数(请求方式为 post)

名称 类型 是否必须 描述
cipIndex Integer 是 基于密码中台的虚拟索引
keyUsageType KeyUsageType-枚举 是 密钥用法类型-ENCRYPTION:加密;SIGNATURE:签名
privateKey byte[] 是 私钥值
pubX byte[] 是 公钥X坐标值
pubY byte[] 是 公钥Y坐标值

三、响应参数

字段名称 描述
errorCode 此次请求的结果 0-此次请求成功 其他-此次请求异常
msg 此次请求结果的描述,success-成功 其他-异常参见异常码
data 此次请求响应的负载,接口的响应信息主体
字段名称 描述
importResult true/false

四、成功示例

JSON示例

{
"errorCode": 0,
"msg": "success",
"requestId": "a0bddb76b98447408921e539ef4c5519",
"data": {
"importResult": ...
},
"success":true
}

五、失败示例

JSON示例

{
"errorCode": 10000,
"msg": "SM2密钥对导入失败",
}

获取中台服务器信息

获取中台服务器信息

一、请求说明

二、请求方式为 get(无参API接口)

代码实例

public class CipBizServiceTest  {

/**
* 获取中台服务器信息
*/
@Test
public void serverInfoTest() throws ApiException {
// 提供的服务地址map集合
HashMap<String, String> map = new HashMap<String, String>();
map.put("cip.api.gf.demo.smartcert.cn", "cn-beijing-1");
map.put("cip.api.gx.demo.smartcert.cn","cn-nanjing-1");
// 优先地域
String location = "cn-nanjing";
// 备用地域集合
List<String> reserveLocation = new ArrayList<String>();
reserveLocation.add("cn-beijing");
// 您的appKey
String appKey = "w8MuGC9C";
// 您的secretKey
String secretKey = "4wVznIMB";
// 构造接口实例
ApiClient apiClient = new DefaultApiClient(map, location, reserveLocation, appKey, secretKey);
CipBizService cipBizServiceEnc = new CipBizServerImpl(apiClient);
// 中台服务器信息获取请求数据
ServerInfoRequest serverInfoRequest = new ServerInfoRequest();
// 中台服务器信息获取
ServerInfoResponse response = cipBizServiceEnc.getServerInfo(serverInfoRequest);
//后续业务处理
System.out.println("================================");
System.out.println("响应内容:" + response);
System.out.println("================================");
System.out.println("SDK请求ID:" + response.getRequestId());
System.out.println("SDK响应消息:" + response.getMsg());
System.out.println("SDK响应码:" + response.getErrorCode());
System.out.println("================================");
if (null != response.getData()) {
System.out.println("中台服务器HTTP信息:" + response.getData().getHttpMap());
System.out.println("中台服务器TCP信息:" + response.getData().getTcpMap());
System.out.println("中台服务器代理信息:" + response.getData().getAgentAddressMap());
System.out.println("中台服务器JSON信息:" + response.getData().getServerInfo());
}
}
}

三、响应参数

字段名称 描述
errorCode 此次请求的结果 0-此次请求成功 其他-此次请求异常
msg 此次请求结果的描述,success-成功 其他-异常参见异常码
data 此次请求响应的负载,接口的响应信息主体
字段名称 描述
serverInfo 中台服务器信息的JSON字符串
httpMap 中台服务器HTTP信息的Map集合
tcpMap 中台服务器TCP信息的Map集合
agentAddressMap 中台服务器代理信息的Map集合

四、成功示例

JSON示例

{
"errorCode": 0,
"msg": "success",
"requestId": "a0bddb76b98447408921e539ef4c5519",
"data": {
"serverInfo": ...,
"httpMap": ...,
"tcpMap": ...,
"agentAddressMap": ...,
},
"success":true

}

五、失败示例

JSON示例

{
"errorCode": 10000,
"msg": "获取中台服务器信息失败",
}e

备注