|
|
@ -442,7 +442,7 @@ function test_aliecc() { |
|
|
|
}; |
|
|
|
}; |
|
|
|
let appId = "5dde4e1bdf9e4966b387ba58f4b3fdc3"; |
|
|
|
let appId = "5dde4e1bdf9e4966b387ba58f4b3fdc3"; |
|
|
|
let nonce = 0; |
|
|
|
let nonce = 0; |
|
|
|
|
|
|
|
/* |
|
|
|
// 生成私钥和公钥
|
|
|
|
// 生成私钥和公钥
|
|
|
|
let private_key = BigInt(Math.floor(Math.random() * 2 ** 32)); |
|
|
|
let private_key = BigInt(Math.floor(Math.random() * 2 ** 32)); |
|
|
|
let ecc_pri = new ECDSA.ECDSA(private_key, "secp256k1"); |
|
|
|
let ecc_pri = new ECDSA.ECDSA(private_key, "secp256k1"); |
|
|
@ -452,7 +452,7 @@ function test_aliecc() { |
|
|
|
function r(appId, deviceId, userId, nonce) { |
|
|
|
function r(appId, deviceId, userId, nonce) { |
|
|
|
return `${appId}:${deviceId}:${userId}:${nonce}`; |
|
|
|
return `${appId}:${deviceId}:${userId}:${nonce}`; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function sign(appId, deviceId, userId, nonce) { |
|
|
|
function sign(appId, deviceId, userId, nonce) { |
|
|
|
let sign_dat = ecc_pri.sign( |
|
|
|
let sign_dat = ecc_pri.sign( |
|
|
|
r(appId, deviceId, userId, nonce).getBytes('utf-8'), |
|
|
|
r(appId, deviceId, userId, nonce).getBytes('utf-8'), |
|
|
@ -460,6 +460,29 @@ function test_aliecc() { |
|
|
|
); |
|
|
|
); |
|
|
|
return sign_dat.toString() + "01"; |
|
|
|
return sign_dat.toString() + "01"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
// 生成私钥和公钥
|
|
|
|
|
|
|
|
let private_key = new Uint8Array(32); // 32 个随机字节
|
|
|
|
|
|
|
|
let public_key = new Uint8Array(64); // 64 个随机字节
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function r(appId, deviceId, userId, nonce) { |
|
|
|
|
|
|
|
return `${appId}:${deviceId}:${userId}:${nonce}`; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function sign(appId, deviceId, userId, nonce) { |
|
|
|
|
|
|
|
eval(getCryptoJS()); |
|
|
|
|
|
|
|
let msg = r(appId, deviceId, userId, nonce); |
|
|
|
|
|
|
|
let hash = CryptoJS.subtle.digest("SHA-256", new TextEncoder().encode(msg)); |
|
|
|
|
|
|
|
let signature = CryptoJS.subtle.sign( |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
name: "ECDSA", |
|
|
|
|
|
|
|
hash: { name: "SHA-256" }, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
private_key, |
|
|
|
|
|
|
|
hash
|
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
return new Uint8Array(signature); |
|
|
|
|
|
|
|
} |
|
|
|
let signature = sign(appId, "3a9935208f4b4fce95a9655c7725d640", "3426ad8ebaa04e1ea9ee01bd998d06d4", nonce); |
|
|
|
let signature = sign(appId, "3a9935208f4b4fce95a9655c7725d640", "3426ad8ebaa04e1ea9ee01bd998d06d4", nonce); |
|
|
|
log(signature); |
|
|
|
log(signature); |
|
|
|
headers['x-signature'] = signature; |
|
|
|
headers['x-signature'] = signature; |
|
|
|