Current location - Quotes Website - Signature design - About the sig field of Tencent Cloud SMS interface, sha256 encryption issue, nodejs
About the sig field of Tencent Cloud SMS interface, sha256 encryption issue, nodejs

Follow my writing method below: const?crypto?=?require('crypto');

function?sig()

{

var?strMobile?=?"This is my mobile phone";?//The content of tel's mobile field

var?strAppKey?=?"This is my key";?/ The appkey corresponding to /sdkappid needs to be highly confidential from the business party

var?strRand?=?"7226249334";?//The value of the random field in the url

var?strTime?= ?"1457336869";?//unix timestamp

var?buf?=?"appkey="+strAppKey+"&random="+strRand+"&time="

+strTime+" &mobile="+strMobile;

var?sig?=?crypto.createHash('sha256').update(buf,?'utf-8').digest('hex');

return?sig;

}

console.log(sig());

The output results are as follows: 7b1e97051886abdbd66c684530db2ba01644f828f31e06d624d88aff5469faa0

The reason is that the document emphasizes that encoding should use utf-8, but the default encoding of js is not this, so it needs to be specified forcefully.

In addition, the calculation result of this sig is related to your output parameters and is not constant.

Also, your mobile and appkey are all in Chinese. The official ones seem to be numbers and letters.