All Products
Search
Document Center

Marketplace:Compute Signature

Last Updated:Jun 17, 2026

Every API request to the IoT platform must carry a signature. Use your key ID and secret key to compute the HMAC-SHA1 signature and add it to the request.

Important

DISCLAIMER

Please note that all content presented on this page is provided by Tuya (HK) Limited. Alibaba Cloud makes no representations and warranties, explicit or implied, as to the authenticity or accuracy of any such content, nor makes any guarantee to the condition, quality, durability, performance, reliability, merchantability or fitness for a particular purpose, or non-infringement of any products and/or services made available by Tuya (HK) Limited. 

The IoT platform authenticates the sender of each API request. All API requests must include signature information.

Description The platform provides Java signature sample code that you can use to quickly generate signatures. Download java signature sample code

The following sections describe the detailed steps for computing a signature.

1. Get the key ID and key

Before computing the signature, prepare the following parameters. Go to the AccessKey management page in the console to view your key ID and key . The key ID identifies the caller. The key encrypts and verifies the signature string on the server side and must be strictly confidential .

2. Signature method

Sign the request as follows:

2.1. Construct a Canonicalized Query String using the request parameters.

a. Sort parameters. Sort the request parameters in lexicographic order by parameter name (including Common parametersand interface parameters, but excluding the Signature parameter itself).

Description When using the GET method to submit a request, these parameters are the part of the request URL after the question mark (?), connected by ampersand (&) characters.

b. URL-encode the name and value of each request parameter. Use the UTF-8 character set and follow the RFC3986 encoding rules: ■Characters A ~ Z, a ~ z, 0~9, and characters - , _ , . , ~ are not encoded. ■Other characters are encoded in %XY format, where XY is the hexadecimal representation of the character's ASCII code. For example, the English double quotation mark " is encoded as %22. ■Extended UTF-8 characters are encoded in %XY%ZA&help; format. ■Spaces must be encoded as %20 instead of a plus sign +. This encoding method is similar to, but different from, the application/x-www-form-urlencoded MIME format encoding algorithm. If you use the Java standard library java.net.URLEncoder, first call percentEncode to encode the value, then replace + with %20, * with %2A, and %7E with ~ to obtain the correctly encoded string.

private static final String ENCODING = "UTF-8";
private static String percentEncode(String value) throws UnsupportedEncodingException {
    return value != null ? URLEncoder.encode(value, ENCODING).replace("+", "%20").replace("*", "%2A").replace("%7E", "~") : null;
}

c. Connect each encoded parameter name and value with an equal sign (=). d. Join the resulting name=value pairs in lexicographic order of the parameter names with ampersand (&) characters. This produces the canonicalized request string (CanonicalizedQueryString).

2.2. Construct a signature string.

Use percentEncode to process the canonicalized string obtained in step 1 and construct the string for computing the signature. Refer to the following rule:

StringToSign=
  HTTPMethod + "&" +                      
  percentEncode("/") + "&" +              
  percentEncode(CanonicalizedQueryString)

Parameter description: ○HTTPMethod: The HTTP method used to send the request, such as GET. ○percentEncode("/"): The value obtained by UTF-8 encoding the character "/", which is "%2F". ○percentEncode(CanonicalizedQueryString): The canonicalized request string from step 1.

2.3. Calculate the HMAC value.

As defined in RFC2104, use the StringToSign obtained in step 2 to compute the HMAC value.

HMAC-SHA1( AccessSecret, UTF-8-Encoding-Of(StringToSign) )

Important The key used to compute the signature is your AccessKeySecret followed by an ampersand (&) character (ASCII:38). The hash algorithm used is HMAC-SHA1.

2.4. Calculate the signature value.

Base64-encode the HMAC value from step 3 to obtain the Signature value.

Signature = Base64( HMAC-SHA1( AccessSecret, UTF-8-Encoding-Of(StringToSign) ) )

1

Signature=Base64(HMAC-SHA1(AccessSecret,UTF-8-Encoding-Of(StringToSign)))

2.5. Add a signature.

Use the resulting signature value as the Signature parameter. URL-encode it according to RFC3986, and then add it to the request parameters to complete the signing process.