-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCheckIdCardInformation.java
50 lines (41 loc) · 2.45 KB
/
CheckIdCardInformation.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.tencentcloud.faceid.example;
import com.alibaba.fastjson.JSON;
import com.tencentcloud.faceid.CryptoUtil;
import com.tencentcloud.faceid.core.Algorithm;
import com.tencentcloud.faceid.core.CryptoProvider;
import com.tencentcloudapi.common.AbstractModel;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.faceid.v20180301.FaceidClient;
import com.tencentcloudapi.faceid.v20180301.models.CheckIdCardInformationRequest;
import com.tencentcloudapi.faceid.v20180301.models.CheckIdCardInformationResponse;
/**
* 身份证人像照片验真
*/
public class CheckIdCardInformation {
private static final String REGION = "ap-guangzhou";
private static final String SECRET_ID = ""; // TODO 腾讯云密钥
private static final String SECRET_KEY = ""; // TODO 腾讯云密钥
private static final Algorithm algorithm = Algorithm.SM4GCM; // 选择加密算法 Algorithm.AES256CBC、Algorithm.SM4GCM
public static void main(String[] args) throws Exception {
// Step 1. 生成对称密钥,用于加解密敏感信息
String key = CryptoProvider.generateKey(algorithm);
// Step 2. 生成加密参数
String ciphertextDesc = JSON.toJSONString(CryptoUtil.bodyEncrypt(algorithm, key, null));
System.out.println("ciphertext desc: " + JSON.toJSONString(ciphertextDesc));
// Step 3. TODO 根据您的业务需要,设置请求参数,详情参考api文档:https://cloud.tencent.com/document/product/1007/47276
CheckIdCardInformationRequest request = AbstractModel.fromJsonString(ciphertextDesc, CheckIdCardInformationRequest.class);
request.setImageBase64("");
request.setIsEncryptResponse(true);
// Step 4. 发起调用
Credential credential = new Credential(SECRET_ID, SECRET_KEY);
FaceidClient client = new FaceidClient(credential, REGION);
CheckIdCardInformationResponse response = client.CheckIdCardInformation(request);
System.out.println("ciphertext response: " + AbstractModel.toJsonString(response));
// Step 5. 解密响应体
String plaintext;
plaintext = CryptoUtil.bodyDecrypt(algorithm, key, response.getEncryption().getIv(),
response.getEncryption().getTagList(), response.getEncryptedBody());
response = AbstractModel.fromJsonString(plaintext, CheckIdCardInformationResponse.class);
System.out.println("plaintext response: " + AbstractModel.toJsonString(response));
}
}