Web Crypto API: importKey does not work in Firefox

那年仲夏 提交于 2019-12-11 13:53:04

问题


I tried this example for importKey in Google Chrome 46 and Firefox 41 (JSBin):

window.crypto.subtle.importKey(
    "jwk", //can be "jwk" (public or private), "spki" (public only), or "pkcs8" (private only)
    {   //this is an example jwk key, other key types are Uint8Array objects
        kty: "RSA",
        e: "AQAB",
        n: "vGO3eU16ag9zRkJ4AK8ZUZrjbtp5xWK0LyFMNT8933evJoHeczexMUzSiXaLrEFSyQZortk81zJH3y41MBO_UFDO_X0crAquNrkjZDrf9Scc5-MdxlWU2Jl7Gc4Z18AC9aNibWVmXhgvHYkEoFdLCFG-2Sq-qIyW4KFkjan05IE",
        alg: "PS256",
        ext: true,
    },
    {   //these are the algorithm options
        name: "RSA-PSS",
        hash: {name: "SHA-256"}, //can be "SHA-1", "SHA-256", "SHA-384", or "SHA-512"
    },
    false, //whether the key is extractable (i.e. can be used in exportKey)
    ["verify"] //"verify" for public key import, "sign" for private key imports
)
.then(
  result => console.log('Ok', result),
  e => console.error(e.message)
)

It works in Chrome, but I get An invalid or illegal string was specified error in Firefox. Which string is invalid or illegal and why?


回答1:


Firefox does not yet support the RSA-PSS algorithm. You can track the bug to implement it for WebCrypto at Bug 1191936.



来源:https://stackoverflow.com/questions/33437075/web-crypto-api-importkey-does-not-work-in-firefox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!