com.aliyun.dkms.gcs.sdk.samples.option.AsymmetricEncrypt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of alibabacloud-dkms-gcs-sdk-samples Show documentation
Show all versions of alibabacloud-dkms-gcs-sdk-samples Show documentation
Dedicated Key Management Service SDK for Java
Copyright (C) Alibaba Cloud Computing
All rights reserved.
版权所有 (C)阿里云计算有限公司
http://www.aliyun.com
The newest version!
package com.aliyun.dkms.gcs.sdk.samples.option;
import com.aliyun.dkms.gcs.openapi.models.Config;
import com.aliyun.dkms.gcs.openapi.util.models.RuntimeOptions;
import com.aliyun.dkms.gcs.sdk.Client;
import com.aliyun.dkms.gcs.sdk.models.EncryptResponse;
import com.aliyun.tea.TeaException;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.kms.model.v20160120.*;
import com.aliyuncs.profile.DefaultProfile;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
public class AsymmetricEncrypt {
public static void main(String[] args) {
asymmetricEncryptKmsSample();
asymmetricEncryptDKmsSample();
}
/**
* 共享kms非对称加密sample
*/
public static void asymmetricEncryptKmsSample() {
DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "", "");
/** use STS Token
DefaultProfile profile = DefaultProfile.getProfile(
"", // The region ID
"", // The AccessKey ID of the RAM account
"", // The AccessKey Secret of the RAM account
""); // STS Token
**/
IAcsClient client = new DefaultAcsClient(profile);
AsymmetricEncryptRequest request = new AsymmetricEncryptRequest();
request.setPlaintext("");
request.setKeyId("");
request.setKeyVersionId("");
request.setAlgorithm("");
try {
AsymmetricEncryptResponse response = client.getAcsResponse(request);
System.out.printf("CiphertextBlob: %s%n", response.getCiphertextBlob());
System.out.printf("KeyId: %s%n", response.getKeyId());
System.out.printf("KeyVersionId: %s%n", response.getKeyVersionId());
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
System.out.println("ErrCode:" + e.getErrCode());
System.out.println("ErrMsg:" + e.getErrMsg());
System.out.println("RequestId:" + e.getRequestId());
}
}
/**
* 专属kms非对称加密sample
*/
public static void asymmetricEncryptDKmsSample() {
Config config = new Config();
config.setProtocol("https");
config.setClientKeyFile("");
config.setPassword("");
config.setEndpoint("");
config.setProtocol("https");
// 验证服务端证书,这里需要设置为您的服务端证书路径
config.setCaFilePath("");
// 或者,设置为您的服务端证书内容
//config.setCa("