我有以下JavaScript代码来使用Web加密API实现公钥加密。它适用于Firefox和Chrome,但Microsoft Edge无法使用。我从Edge获得的错误是“由于错误80700011而无法完成操作”。我错过了什么?Microsoft Edge中的公钥加密
<script>
var data = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
var crypto = window.crypto || window.msCrypto;
var cryptoSubtle = crypto.subtle;
cryptoSubtle.generateKey(
{
name: "RSA-OAEP",
modulusLength: 2048,
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
hash: { name: "SHA-256" },
},
true,
["encrypt", "decrypt"]
).then(function (key) {
console.log(key);
console.log(key.publicKey);
return cryptoSubtle.encrypt(
{
name: "RSA-OAEP"
},
key.publicKey,
data
);
}).then(function (encrypted) {
console.log(new Uint8Array(encrypted));
}).catch(function (err) {
console.error(err);
});
</script>
“W3CException_DOM_TYPE_MISMATCH_ERR:节点类型是与预期的参数类型不兼容。”也许不是很有帮助,但这是我能找到的。也许它表明问题在代码中的其他地方。 –
谢谢@JamesKPolk。没有别的。这是一个带有上述代码的空白页面。它也适用于Firefox和Chrome。 – FengHuang