KMS-SDK allows you to call KMS APIs by simple programming to encrypt and decrypt data, sign data, verify signatures, and manage keys. This section introduces how to initialize the SDK and how to invoke APIs.
Before You Begin
You have purchased subscription-based KMS.
You have created an application access point and obtained the KMS application access point address.
You have created the access credentials AK/SK.
You have created the key resource.
Download the SDK
Please click the link to download SDK: SDK.zip
Environment dependency
You only need to import the SDK into the Java project and add the following dependencies in the configuration file to use the functions of KMS-SDK.
<dependency>
<groupId>org.kmssdk</groupId>
<artifactId>ctyun_kms_sdk_java</artifactId>
<version>1.0</version>
</dependency>
How to Call
The following figure shows how to use the Java SDK APIs provided by KMS.
First, initialize the DefaultProfile class, specify parameters AK, SK and application access point address, then initialize the DefaultKmsClient class and specify the DefaultProfile class of the previous step.
You need to create the Request class for the API to be called, specify the parameters, and send the HTTP/HTTPS request.
You can change the request protocol for the Request class. The default protocol is HTTPS.
The response results are received through the created Response class and ResponseData class, and the specific data is obtained by using the get method.
Initialize SDK
When invoking an API using the Java SDK, first initialize the DefaultProfile class and the DefaultKmsClient class.
Example:
// First initialize the DefaultProfile class, new DefaultProfile (String ak, String sk, String ipport), specify the user's AK, SK, and access point address
DefaultProfile defaultProfile = new DefaultProfile("ae2cc5cc5e8211ea978a186590d96509", "bf9ebf2fb797d85818f46d136a8637388c988813", "127.0.0.1:9091");
//Initialize the DefaultKmsClient class, and specify the DefaultProfile class of the previous step.
DefaultKmsClient defaultKmsClient = new DefaultKmsClient(defaultProfile);