【发布时间】:2016-01-07 16:29:32
【问题描述】:
我有以下 JavaScript 代码来使用 Web Cryptography API 实现公钥加密。它适用于 Firefox 和 Chrome,但不适用于 Microsoft Edge。我从 Edge 得到的错误是“由于错误 80700011 无法完成操作。”我错过了什么?
<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。
标签: encryption microsoft-edge public-key-encryption webcrypto-api