Reputation: 4267
I'm trying to use crypto module in js and subtleCrypto to encode a string with a public key. I want to give the public key as a string but my code in subtle crypto throws error that "parameter 2 is not of type 'CryptoKey'. here's my code:
const handleEncodeClick = () => {
const crypto = window.crypto.subtle;
crypto.encrypt({name: "RSA-OAEP"}, publicKey, new TextEncoder().encode(myMsg))
.then(encrypted => {
setEncoded(new Uint8Array(encrypted));
})
.catch(err => {
console.log(err);
});
};
Upvotes: 1
Views: 2172