I'm trying to create a web application to generate RSA public/private key pairs and I'm testing my code.
(async function() {
const subtle = crypto.subtle;
const keyConfig = {
name: "RSA-OAEP",
modulusLength: 2048,
publicExponent: new Uint8Array([1,0,1]),
hash: "SHA-256"
}
const key = await subtle.generateKey(keyConfig, true, ["encrypt", "decrypt"]);
const public = key.publicKey;
const private = key.privateKey;
const exported_public = subtle.exportKey("pkcs8", public)
.then(arr => {
alert(arr) // I know it's an ArrayBuffer
})
.catch(err => {
alert(err)
});
})();
In this case the .catch statement is alerting the error "InvalidAccessError: The key is not of the expected type". I did a quick google search and nothing came up. How do I fix this?