diff --git a/README.md b/README.md index 1769cec2..5e4a7389 100644 --- a/README.md +++ b/README.md @@ -198,6 +198,40 @@ const encryptDecryptFunction = async() => { encryptDecryptFunction() ``` +Encrypt with multiple public keys: + +```js +const pubkey1 = `-----BEGIN PGP PUBLIC KEY BLOCK----- +... +-----END PGP PUBLIC KEY BLOCK-----` +const pubkey2 = `-----BEGIN PGP PUBLIC KEY BLOCK----- +... +-----END PGP PUBLIC KEY BLOCK-----` +const privkey = `-----BEGIN PGP PRIVATE KEY BLOCK----- +... +-----END PGP PRIVATE KEY BLOCK-----` //encrypted private key +const passphrase = `yourPassphrase` //what the privKey is encrypted with + +const encryptWithMultiplePublicKeys = async() => { + const privKeyObj = (await openpgp.key.readArmored(privkey)).keys[0] + await privKeyObj.decrypt(passphrase) + + const options = { + message: openpgp.message.fromText('Hello, World!'), // input as Message object + publicKeys: [ // for encryption + openpgp.key.readArmored(pubkey1).keys[0], + openpgp.key.readArmored(pubkey2).keys[0] + ], + privateKeys: [privKeyObj] // for signing (optional) + } + + openpgp.encrypt(options).then(ciphertext => { + encrypted = ciphertext.data // '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----' + return encrypted + }) + }; +``` + #### Encrypt with compression By default, `encrypt` will not use any compression. It's possible to override that behavior in two ways: @@ -344,16 +378,6 @@ openpgp.generateKey(options).then(function(key) { }); ``` -#### Encrypt with multiple public keys - -```js - publicKeys: [ // for encryption - openpgp.key.readArmored(pubkey1).keys[0], - openpgp.key.readArmored(pubkey2).keys[0] - ] - }; -``` - #### Revoke a key Using a revocation signature: