javascriptencryptionrsapublic-key

encrypt to multiple public keys with RSA using Webcrypto


is there any way to encrypt data for multiple public key (so multiple key owner can decrypt data using their private key) using javascript cryto Api.

If that is not possible using RSA-OAEP, can you please suggest way for the same?

Thanks

window.crypto.subtle.encrypt(
    {
        name: "RSA-OAEP",

    },
    ArrayOfPublicKeys, 
    data 
)
.then(function(encrypted){

    console.log(encrypted);
})

Solution

  • Dr Jack Millan.

    The way PGP, S/MIME and other similar messaging solutions enable a multi-party message is to:

    1. Generate a Message Encryption Key (MEK), for example, an AES key for use with mode GCM,
    2. Look up the public key of each recipient,
    3. Encrypt the MEK to each recipient's public key,
    4. Package the encrypted MEKs with the encrypted message,
    5. Distribute to participants.

    The challenge here is the secure discovery of public keys, most applications punt on this and make the user do manual thumbprint verification or rely on a third-party such as a Certificate Authority to verify the binding of a key to a subject.

    You can find an example that does this using webcrypto with a single recipient here: https://pkijs.org/examples/CMSEnvelopedExample.html

    The source for this demo is here: https://github.com/PeculiarVentures/PKI.js/tree/master/examples/HowToEncryptCMSviaCertificate