0

To decrypt something with the Web Crypto API you have to first import the key thusly:

const result = crypto.subtle.importKey(
    format,
    keyData,
    algorithm,
    extractable,
    usages
);

This returns a promise. If you append .then(function(importedKey) {}) to that you'll be able to use the actual imported key to decrypt:

const result = crypto.subtle.decrypt(algorithm, key, data);

My question is... since the imported key object already has the algorithm specified why do you need to respecify the algorithm when trying to do the actual decryption?

Related to this, importKey seems to support RSASSA-PKCS1-v1_5 as an algorithm but decrypt doesn't. If decrypt() doesn't support RSASSA-PKCS1-v1_5 then why does importKey?

neubert
  • 15,947
  • 24
  • 120
  • 212
  • RSASSA-PKCS1-v1_5 is a signature scheme, so not used for encryption. – Ry- Sep 07 '20 at 23:29
  • @Ry- - good point. I guess I got RSASSA-PKCS1-v1_5 and RSAES-PKCS1-v1_5 confused. In my head I just remember "PKCS1" - I don't remember the bits that come before. My first question still stands tho. If I specify OAEP for `importKey` then why do I need to specify it again for `decrypt`? Seems redundant... – neubert Sep 07 '20 at 23:54

0 Answers0