I would like to be able to encrypt data using public keys, and decrypt the encrypted data using private keys.
Encryption essentially needs to accept inputs:
- Clear data to be encrypted
- A list of several public keys
- The minimum number of private keys corresponding to those public keys that are needed to decrypt the encrypted
How can this be done in NodeJs?
Scenarios
By way of concrete scenarios, where there are 5 users (A - E) with crypto key pairs in the system.
A 1-of-X scenario:
encrypted = crypto_encrypt(clearText, [A.publicKey, B.publicKey], 1)(1-of-2)decrypted = crypto_decrypt(encrypted, [A.privateKey])- success:
decrypted === clearText - because
A.publicKeywas used in encryption
- success:
decrypted = crypto_decrypt(encrypted, [C.privateKey])- failure: unable to decrypt
- because
C.publicKeywas not used in encryption
A Y-of-X scenario:
encrypted = crypto_encrypt(clearText, [A.publicKey, B.publicKey, C.publicKey], 2)(2-of-3)decrypted = crypto_decrypt(encrypted, [A.privateKey, C.privateKey])- success:
decrypted === clearText - because both
A.publicKeyandC.publicKeywas used in encryption
- success:
decrypted = crypto_decrypt(encrypted, [C.privateKey, E.privateKey])- failure: unable to decrypt
- because while
C.publicKeywas used in encryption,E.publicKeywas not
Ideally...
- At minimum I need to be able to support the 1-of-X scenario, but if Y-of-X is also possible, that would be better
- What the actual key pairs are is not so important here, could be RSA, could be any of the elliptic curves. If the method supports a number of different ones, and allows one to pick, that would be better
- Preferably not tied to the use of any particular toolset or framework