【发布时间】:2020-06-01 22:08:10
【问题描述】:
以下代码适用于 Firefox 76.0.1:
"use strict"
let RSAKeys
(async () => {
RSAKeys = await crypto.subtle.generateKey({
name: "RSA-OAEP",
modulusLength: 3072,
publicExponent: new Uint8Array([1, 0, 1]),
hash: "SHA-256"},
true,
["wrapKey", "unwrapKey"])
alert(JSON.stringify(Object.fromEntries(
await Promise.all(Object.entries(RSAKeys).map(async ([k, v], i) =>
[k, await cryptoBase64("exportKey", ["pkcs8", "spki"][i], v)])))))
})()
async function cryptoBase64(primitive, ...args) {
return ArrayBufferToBase64(await crypto.subtle[primitive](...args))
}
function ArrayBufferToBase64(buf) {
return btoa([...new Uint8Array(buf)].map(x => String.fromCharCode(x)).join(""))
}
但在 Chromium 80 中我得到:
未捕获(承诺中)DOMException:密钥不是预期的类型
差异在哪里?它是 Chromium 中的错误吗?是否有解决方法?
(与this question相关。应用解决方案后我仍然遇到问题,结果发现我遇到的浏览器之间存在另一个差异。)
【问题讨论】:
标签: google-chrome rsa chromium webcrypto-api