On the client I am generating a CryptoKeyPair
object using the WebCrypto
API. I want to send this key pair to my express server using the fetch API, but all I get in req.body
is an empty object. Why this is happening?
Generating keys:
const keyPair = await crypto.subtle.generateKey(RsaOaepParams, true, ["encrypt", "decrypt"]);
POST request:
fetch('/', {
method: 'POST',
body: JSON.stringify(keyPair.publicKey),
headers: {
'Content-Type': 'application/json'
},
})
No, this is not a problem with the bodyParser
middleware. I have configured it properly. JSON.stringify(keyPair.publicKey)
itself is turning the object empty
To access the RSA Public Key requires several items:
Note: Your example code expects the JWK format. Typically, public keys are exported in SPKI format. See the second example.
JWK format for exporting a public key:
SPKI format for exporting a public key: