Encryption Signature
Headers required for the API access signature algorithm:
Request Header | Required | Description |
---|---|---|
X-Gw-Signature-Method | Yes | Encryption algorithm, currently only supports hmac-sha256 |
X-Gw-Signature-Headers | Yes | Request headers needed for signature, fill in X-Gw-Timestamp, X-Gw-App-Key |
X-Gw-App-Key | Yes | Signature AppKey, get it from the App detail page in the console |
X-Gw-Timestamp | Yes | UNIX signature timestamp |
X-Gw-SignedString | Yes | Signed string, the format is “X-Gw-Timestamp:” + Signature timestamp + “,X-Gw-App-Key:” + AppKey |
X-Gw-Signature | Yes | Signature value |
X-Gw-Stage | No | If the call environment is a RELEASE environment, it is not required; API calls subscribed in the API market do not need to be filled in |
NodeJs version signature code
var axios = require("axios")
var CryptoJS = require("crypto-js");
var signHeaders = "X-Gw-Timestamp,X-Gw-App-Key"
var appKey = "xxxxxxxxxxxxxxxxxxxx"
var appSecret = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
var timeStamp = Math.ceil(Date.now() / 1000)
var signedString = "X-Gw-Timestamp:" + timeStamp + ",X-Gw-App-Key:" + appKey;
var signature = CryptoJS.HmacSHA256(signedString , appSecret).toString(CryptoJS.enc.Base64);
var url = "http://demo.ucloudapi.com/getUserInfo/v1"
axios({
method : "GET",
url : url,
headers : {
"X-Gw-Signature-Method" : "hmac-sha256",
"X-Gw-Signature-Headers" : "X-Gw-Timestamp,X-Gw-App-Key",
"X-Gw-App-Key" : appKey,
"X-Gw-Timestamp" : timeStamp,
"X-Gw-Signature" : signature,
"X-Gw-SignedString" : signedString,
"X-Gw-Stage" : "RELEASE"
}
}).then(function(response){
console.log(response.data)
})