我想生成一个 ECDSA 签名并将其转换为 base64。
我可以使用 Nodejs 轻松完成此任务:
const sign = crypto.createSign('SHA256')
sign.update('part1')
sign.update('part2')
const signature = sign.sign(privateKey, 'base64')
但是,当我尝试对 Javascript SubtleCrypto API 执行相同操作时,生成的签名在使用 Node Crypto 验证时无效。这是我的代码:
let signature = await window.crypto.subtle.sign(
{
name: "ECDSA",
hash: { name: "SHA-256" },
},
this.privateKey,
"part1"+"part2"
);
signature = new Uint8Array(signature);
const byteArray = new Uint8Array(signature);
let byteString = "";
for (let i = 0; i < byteArray.byteLength; i += 1) {
byteString += String.fromCharCode(byteArray[i]);
}
const b64Signature = window.btoa(byteString);
我错过了什么?