我有一条可以用 openssl 解码的 RSA 加密消息:
openssl rsautl -inkey cert.pem -pubin -in encrypted -out plaintext
如何使用 WebCrypto API 实现这一点?尝试以下操作时出现错误:
window.crypto.subtle.importKey(
"spki",
new Uint8Array(pubKey),
{
name: "RSA-OAEP",
hash: {name: "SHA-256"}
},
true,
["verify"]
)
.then(function(publicKey){
console.log(publicKey);
window.crypto.subtle.decrypt(
{
name: "RSA-OAEP"
},
publicKey,
new Uint8Array(encrypted)
)
.then(function(decrypted){
console.log(new Uint8Array(decrypted));
})
.catch(function(err){
console.error(err);
});
})
.catch(function(err){
throw(err);
});