This topic describes how requests are signed. You must sign all HTTP or HTTPS API
requests to ensure security. Alibaba Cloud uses the request signature to verify the
identity of the request sender. Alibaba Cloud Content Delivery Network (CDN) implements
symmetric encryption with an AccessKey pair to verify the identity of the request
sender. An AccessKey pair consists of an AccessKey ID and an AccessKey secret.
AccessKey descriptions
You can obtain the AccessKey ID and AccessKey secret on the AccessKey Management page
in the Alibaba Cloud Management Console. The AccessKey ID is used to verify the identity
of the user, while the AccessKey secret is used to encrypt and verify the signature
string. You must keep your AccessKey secret strictly confidential.
For more information, see Obtain an AccessKey pair.
Procedure
- Create a canonicalized query string.
- Arrange the request parameters (including Common request parameters and operation-specific parameters except Signature) in alphabetical order.
Note If you use the GET method to send a request, the request parameters are included as
a part of the request URL. The first parameter follows the question mark (?
) in the URL and the other parameters follow an ampersand (&
).
- Encode the canonicalized query string in UTF-8 based on RFC 3986.
- Use an equal sign (=) to concatenate each encoded request parameter and its value.
- Use an ampersand (&) to concatenate the encoded request parameters. Note that these
parameters must be arranged in the same order as those in Step 1.
- Create a string-to-sign.
- Create a string-to-sign (Signature) from the encoded canonicalized query string.
You can also use
percentEncode to encode the canonicalized query string created in the previous step. Perform the
following steps to create a string-to-sign:
StringToSign=
HTTPMethod + "&" + // HTTPMethod: HTTP method used to make the request, such as GET.
percentEncode ("/") + "&" + //percentEncode("/"): encode backslashes (/) as %2F.
percentEncode(CanonicalizedQueryString) // encode the canonicalized query string created in Step 1.
- Calculate the HMAC value of the string-to-sign by using the AccessKey secret as the
key.
Calculate the hash-based message authentication code (HMAC) value of the string-to-sign based on RFC 2104.
Note Use the Secure Hash Algorithm 1 (SHA1) algorithm to calculate the HMAC value of the
string-to-sign. The AccessKey secret appended with an ampersand (&
) (ASCII: 38) is used as the key for the HMAC calculation.
- Obtain the signature string.
Encode the HMAC value in Base64 to obtain the signature string (Signature).
- Add the signature string to the request.
Add the signature string to the request as the
Signature parameter. The result is the signed API request.
Note The signature string is submitted to the server based on
RFC 3986.