I'm so sorry for the ambiguous title of this question, i'm not really sure how to phrase this.
I've generated a Public and Private key using SubtleCrypto in NodeJS like so:
const { publicKey, privateKey } = await subtle.generateKey({
name: 'RSA-OAEP',
4096,
new Uint8Array([1, 0, 1]),
'SHA-256',
}, true, ['encrypt', 'decrypt']);
And this works perfectly for one use case:
Public Key to Encrypt, Private Key to Decrypt.
However, the way I wish to implement RSA in my project is as such:
- Client asks Server for a Public Key
- Client encrypts payload using Public Key
- Server decrypts payload using Private Key
- Server encrypts response payload using Private Key
- Client decrypts response payload using Public Key
When I try to perform Step 4
, i encountered this error:
The requested operation is not valid for the provided key
Is there a way to specify that each key could be used for Encrypt & Decrypt
?
Also if my implementation is completely wrong, i'm sorry for that.