I am trying encrypt text with OpenPGP.js.
Here is an example of error: https://jsfiddle.net/7e2s516d/
let publicKeyArmored = `-----BEGIN PGP PUBLIC KEY BLOCK-----
xjMEYLTYzBYJKwYBBAHaRw8BAQdAoatyco6C3CO87ZxgjIfWsFv3RMxs5W1F
EinwU2UiQ+bNF3Rlc3QgPHRlc3RAZXhhbXBsZS5vcmc+wowEEBYKAB0FAmC0
2MwECwkHCAMVCAoEFgACAQIZAQIbAwIeAQAhCRC+iM+wNlG7chYhBFZgyLBQ
Cavx4mET576Iz7A2UbtyVa8BAP1oFrSwoGdd7+dgBUu7KwU02wvrtuqyURe5
GFSTyMn2AQDWTsJjgYq7hPqSQoeZ30xN0eUoiUiyIA/ffqhM2qHPD844BGC0
2MwSCisGAQQBl1UBBQEBB0CxgKqNlcBTkuaFRvYm/UbR8ZKFFda0tnUCTzl/
tgCsJgMBCAfCeAQYFggACQUCYLTYzAIbDAAhCRC+iM+wNlG7chYhBFZgyLBQ
Cavx4mET576Iz7A2UbtysPgA/0pn4n3QqBBc56/okcGFdC78LEwDLN/ZLkY6
azfQ1aqwAP0d9CWw9ywheGtB1SBCzHZbToKaltVFCNT1ArSUFK45Dg==
=pnHg
-----END PGP PUBLIC KEY BLOCK-----
`;
let messageEncrypt = openpgp.encrypt({
message: openpgp.createMessage({ text: 'test' }),
publicKeys: openpgp.readKey({ armoredKey: publicKeyArmored })
});
console.log(messageEncrypt);
I am using the latest version (5.0.0-3) of OpenPGP.js
It looks like you didn't check documentation of those functions.
encrypt,createMessageandreadKeyare returning aPromise, not a simple value (i.e.MessageorPublicKey). Therefore you need to use those promises correctly.EncryptOptionsobject that you pass toencryptmethod should not havepublicKeysproperty, butencryptionKeysOnce you do those changes it'll work fine.