Skip to Content
Operation GuideInvoke APIEncryption Signature

Encryption Signature

Headers required for the API access signature algorithm:

Request HeaderRequiredDescription
X-Gw-Signature-MethodYesEncryption algorithm, currently only supports hmac-sha256
X-Gw-Signature-HeadersYesRequest headers needed for signature, fill in X-Gw-Timestamp, X-Gw-App-Key
X-Gw-App-KeyYesSignature AppKey, get it from the App detail page in the console
X-Gw-TimestampYesUNIX signature timestamp
X-Gw-SignedStringYesSigned string, the format is “X-Gw-Timestamp:” + Signature timestamp + “,X-Gw-App-Key:” + AppKey
X-Gw-SignatureYesSignature value
X-Gw-StageNoIf 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) })