Signature algorithm
Data assumption
When generating the signature (Signature
) in the API request, you need to provide the key in the account, including PublicKey
and PrivateKey
,
The key can be obtained from Console.
In this example it is assumed:
PublicKey = 'someone@example.com1296235120854146120'
PrivateKey = '46f09bb9fab4f12dfc160dae12273d5332b5debe'
💡 You can use the above
PublicKey
andPrivateKey
to debug your code. When you get a consistent signature result (which means your code is correct), you can change it to your ownPublicKey
andPrivateKey
` and other API requests.
In this example, it is assumed that the user request parameter string is as follows:
{
"Action" : "DescribeUHostInstance",
"Region" : "cn-bj2",
"Limit" : 10,
"PublicKey" : "someone@example.com1296235120854146120"
}
Generate the SHA1 signature of the signed string, which is the value of the request parameter Signature
.
According to the above algorithm, in this example, the calculated Signature
is cba5cf5ec4d4233d206b1b54951e3787350a642f.
Construct signature
1. Arrange request parameters in ascending order by name
{
"Action" : "DescribeUHostInstance",
"Limit" : 10,
"PublicKey" : "someone@example.com1296235120854146120",
"Region" : "cn-bj2"
}
2. Construct the signed parameter string
The construction rules of the signed string are: signed string = concatenation of all request parameters (no HTTP escaping required). And splice the private key of the API key (PrivateKey
) at the end of this signature string.
ActionDescribeUHostInstanceLimit10PublicKeysomeone@example.com1296235120854146120Regioncn-bj246f09bb9fab4f12dfc160dae12273d5332b5debe
Notice:
- For bool types, should be encoded as
true/false
- For floating point number types, if the fractional part is 0, only the integer part should be retained, such as
42.0
should be retained as42
- For floating point types, scientific notation cannot be used
3. Calculate signature
Use SHA1 to encode the signed string to generate the final signature.