如何在NodeJS中从hmacsha1生成Node JS签名代码
How to genarate NodeJS signature code from hmacsha1 in NodeJS
timestamp 和 device_id 在我请求生成签名的函数时总是会改变,但签名哈希仍然是
ea6b458e9a840b7f93236244bf1ea7cb564a8f08
这个哈希生成代码
let array = [login_type, device_id, timestamp];
let hash = crypto.createHmac('sha1', secret_key).update(implode(array, "|")).digest('hex');
function timeMil(){
var date = new Date();
var timeMil = date.getTime();
return timeMil;
}
const device_id = "2752707c1c745ff8";
const secret_key = "9LXAVCxcITaABNK48pAVgc4muuTNJ4enIKS5YzKyGZ";
const timestamp = timeMil();
let array = [login_type, device_id, timestamp];
let hash = crypto.createHmac('sha1', secret_key).update(implode(array, "|")).digest('hex');
console.log(hash);
Genarated hash_hmac alway is ea6b458e9a840b7f93236244bf1ea7cb564a8f08
JavaScript中没有"implode"函数;它的等效项是在数组上使用 join
:
const crypto = require('crypto');
function timeMil(){
return new Date().getTime();
}
const login_type = 'test';
const device_id = "2752707c1c745ff8";
const secret_key = "9LXAVCxcITaABNK48pAVgc4muuTNJ4enIKS5YzKyGZ";
const timestamp = timeMil();
let array = [login_type, device_id, timestamp];
let hash = crypto.createHmac('sha1', secret_key).update(array.join("|")).digest('hex');
console.log(hash);
timestamp 和 device_id 在我请求生成签名的函数时总是会改变,但签名哈希仍然是
ea6b458e9a840b7f93236244bf1ea7cb564a8f08
这个哈希生成代码
let array = [login_type, device_id, timestamp];
let hash = crypto.createHmac('sha1', secret_key).update(implode(array, "|")).digest('hex');
function timeMil(){
var date = new Date();
var timeMil = date.getTime();
return timeMil;
}
const device_id = "2752707c1c745ff8";
const secret_key = "9LXAVCxcITaABNK48pAVgc4muuTNJ4enIKS5YzKyGZ";
const timestamp = timeMil();
let array = [login_type, device_id, timestamp];
let hash = crypto.createHmac('sha1', secret_key).update(implode(array, "|")).digest('hex');
console.log(hash);
Genarated hash_hmac alway is ea6b458e9a840b7f93236244bf1ea7cb564a8f08
JavaScript中没有"implode"函数;它的等效项是在数组上使用 join
:
const crypto = require('crypto');
function timeMil(){
return new Date().getTime();
}
const login_type = 'test';
const device_id = "2752707c1c745ff8";
const secret_key = "9LXAVCxcITaABNK48pAVgc4muuTNJ4enIKS5YzKyGZ";
const timestamp = timeMil();
let array = [login_type, device_id, timestamp];
let hash = crypto.createHmac('sha1', secret_key).update(array.join("|")).digest('hex');
console.log(hash);