Get token API

Updated at:

This topic describes the request and response parameters for the Get Token API. It also explains how to calculate the secret request parameter.

Basic information

  • Description: Allows tenants to obtain an access token by authenticating their AccessKey (AK) with a signature.

  • Content-Type: application/json;charset=UTF-8

  • HTTP Method: POST

  • Request Path: /api/contract/shakeHand

Request parameters

Parameter name

Required

Type

Description

accessId

Yes

string

The AccessKey ID of the tenant.

time

Yes

string

The timestamp for the signature, in milliseconds.

secret

Yes

string

The signature data. This is a hexadecimal encoded string. The content to be signed is `accessId` + `time`. For more information, see secret calculation logic.

Response parameters

Parameter name

Type

Description

success

boolean

Indicates whether the request was successful.

code

string

The error code.

data

string

- Success: The access token.

- Failed: An error message is displayed.

secret calculation logic

Complete flow

  1. Concatenate the content to be signed.

    Combine the accessId and currentTimestamp parameters into a single string. This string is the content to be signed. For example:

    accessId = "8cf380ba"
    currentTimestamp = "1755684845287"
    contentToSign = "8cf380ba1755684845287"
  2. Load the RSA private key.

    Load and decode the private key from a file to generate a private key object. For example:

    byte[] bytesPrivateBase64 = ...; // The content of the private key file. Remove comment lines, such as `-----BEGIN RSA PRIVATE KEY-----` and `-----END RSA PRIVATE KEY-----`, and keep only the key content.
    byte[] bytesPrivate = Base64.decode(bytesPrivateBase64);
    PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(bytesPrivate);
    KeyFactory keyFactory = null;
    KeyFactory keyFactory = KeyFactory.getInstance("RSA");
    PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
  3. Generate the signature.

    Use the SHA256withRSA algorithm to sign the content. For example:

    Signature signature = Signature.getInstance("Sha256WithRSA");
    signature.initSign(privateKey);
    signature.update(plain.getBytes("UTF-8"));
    byte[] signed = signature.sign();
  4. Convert the signature.

    Convert the signature result into a hexadecimal string. This string is the value for the secret parameter in your request. For example:

    String secret = new String(Hex.encode(signed));

Complete code example

// 1. Concatenate the content to be signed.
String plain = accessId + currentTimestamp; // For example: "8cf380ba1755684845287"

// 2. Load the private key.
byte[] bytesPrivateBase64 = ...; // The content of the private key file.
byte[] bytesPrivate = Base64.decode(bytesPrivateBase64);
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(bytesPrivate);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PrivateKey privateKey = keyFactory.generatePrivate(keySpec);

// 3. Initialize the signature object.
Signature signature = Signature.getInstance("SHA256withRSA");
signature.initSign(privateKey);
signature.update(plain.getBytes("UTF-8"));

// 4. Generate the signature.
byte[] signed = signature.sign();

// 5. Convert to a hexadecimal string.
String secret = new String(Hex.encode(signed));

Notes

Category

Note

Timestamp

Ensure the timestamp is synchronized with the server time to avoid signature validation failure due to time drift.

Private key file

Store the private key file securely to prevent leaks.

Encoding

Ensure the encoding format of the content to be signed, such as UTF-8, is consistent with the format used during signature generation.

Signature algorithm

Use SHA256withRSA to ensure the security and integrity of the signature.