问题
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