# hmac
进行Hmac 支持算法有:HmacSM3 HmacSHA1 HmacSHA256 HmacSHA384 HmacSHA512 HmacMD5
# 一、请求说明
- 请求地址:http://IP:PORT/openapi/ces/v1/hmac
- 服务接口名称(即公共参数method的值): hmac
- 请求方式:POST
# 二、请求参数
| 名称 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| data | String | 是 | 待摘要数据 (原文、base64、hex) |
| dataType | DataType | 是 | 待摘要数据类型 |
| hmacAlgorithm | String | 是 | 算法 (详情请查看字段介绍) |
| digestDataType | DataType | 是 | 摘要后数据类型(base64、hex) |
| hmacKey | String | 是 | 密钥 |
- hmacAlgorithm 摘要算法介绍
支持传入以下字符串:
"HmacSM3""HmacSHA1""HmacSHA256""HmacSHA384""HmacSHA512""HmacMD5"
# 三、响应参数
| data 结果信息 | 类型 | 描述 |
|---|---|---|
| digest | String | 摘要数据 |
# 四、成功示例
JSON示例
{
"code": 0,
"message": "success",
"requestId":"xxx",
"data": {
"digest": "o8Ak8BzMs7Y0V9hIsNL4nB90Sj0="
}
}
# 五、失败示例
JSON示例
{
"code": 10100,
"requestId":"xxx",
"message": "参数校验异常",
}
# 六、SDK请求示例
// 提供的URL
String url = "http://172.16.6.102:9200";
// 您的appKey
String appKey = "yQHIS771zS";
// 您的appSecret
String appSecret = "7Vz6HI9Xo833cUJmXzzXrgSwasEwkYOn";
// 原客户端
PkiClient pkiClient = new PkiOkhttpClient(url, appKey, appSecret);
HmacRequest request = new HmacRequest();
// 待摘要数据
request.setData("123");
// 待摘要数据类型
request.setDataType(DataType.ORIGINAL);
// 摘要算法
request.setHmacAlgorithm("HmacSHA1");
// 摘要后的数据类型
request.setDigestDataType(DataType.BASE64);
// 密钥
request.setHmacKey("123");
try {
HmacResponse response = pkiClient.execute(request);
// 后续业务
if (response.isSuccess()) {
System.out.println("成功:" + response.getResult());
} else {
System.out.println("失败:" + response.getBody());
}
} catch (ApiException e) {
e.printStackTrace();
}
← 数据摘要