Update function to be clear
Update function to be clear and without hardcoded payload
This commit is contained in:
parent
9f8c93dc04
commit
a4276677b8
22
README.md
22
README.md
|
@ -201,31 +201,33 @@ encryptDecryptFunction()
|
||||||
Encrypt with multiple public keys:
|
Encrypt with multiple public keys:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const pubkey1 = `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
const pubkeys = [`-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||||
...
|
...
|
||||||
-----END PGP PUBLIC KEY BLOCK-----`
|
-----END PGP PUBLIC KEY BLOCK-----`,
|
||||||
const pubkey2 = `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
`-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||||
...
|
...
|
||||||
-----END PGP PUBLIC KEY BLOCK-----`
|
-----END PGP PUBLIC KEY BLOCK-----`
|
||||||
const privkey = `-----BEGIN PGP PRIVATE KEY BLOCK-----
|
const privkey = `-----BEGIN PGP PRIVATE KEY BLOCK-----
|
||||||
...
|
...
|
||||||
-----END PGP PRIVATE KEY BLOCK-----` //encrypted private key
|
-----END PGP PRIVATE KEY BLOCK-----` //encrypted private key
|
||||||
const passphrase = `yourPassphrase` //what the privKey is encrypted with
|
const passphrase = `yourPassphrase` //what the privKey is encrypted with
|
||||||
|
const message = 'Hello, World!' // input as Message object
|
||||||
|
|
||||||
const encryptWithMultiplePublicKeys = async() => {
|
async encryptWithMultiplePublicKeys(pubkeys, privkey, passphrase, message) {
|
||||||
const privKeyObj = (await openpgp.key.readArmored(privkey)).keys[0]
|
const privKeyObj = (await openpgp.key.readArmored(privkey)).keys[0]
|
||||||
await privKeyObj.decrypt(passphrase)
|
await privKeyObj.decrypt(passphrase)
|
||||||
|
|
||||||
|
pubkeys = pubkeys.map(async (key) => {
|
||||||
|
return (await openpgp.key.readArmored(key)).keys[0]
|
||||||
|
});
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
message: openpgp.message.fromText('Hello, World!'), // input as Message object
|
message: openpgp.message.fromText(message),
|
||||||
publicKeys: [ // for encryption
|
publicKeys: pubkeys, // for encryption
|
||||||
openpgp.key.readArmored(pubkey1).keys[0],
|
|
||||||
openpgp.key.readArmored(pubkey2).keys[0]
|
|
||||||
],
|
|
||||||
privateKeys: [privKeyObj] // for signing (optional)
|
privateKeys: [privKeyObj] // for signing (optional)
|
||||||
}
|
}
|
||||||
|
|
||||||
openpgp.encrypt(options).then(ciphertext => {
|
return openpgp.encrypt(options).then(ciphertext => {
|
||||||
encrypted = ciphertext.data // '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----'
|
encrypted = ciphertext.data // '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----'
|
||||||
return encrypted
|
return encrypted
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue
Block a user