This is not working for me, openPGP just freezes:
import openpgp from 'openpgp';
const 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 = await openpgp.encrypt({
message: await openpgp.createMessage({ text: 'test' }),
publicKeys: await openpgp.readKeys({ armoredKey: publicKeyArmored }) // This promise never resolves
});
console.log(messageEncrypt);
However, if I read the key from disk using below approach it works:
import { readFileSync } from 'fs';
import openpgp from 'openpgp';
const armoredKeys = readFileSync('./public.key.asc', {
encoding: 'utf8',
});
let messageEncrypt = await openpgp.encrypt({
message: await openpgp.createMessage({ text: 'test' }),
publicKeys: await openpgp.readKeys({ armoredKey: publicKeyArmored })
});
console.log(messageEncrypt); // Totally works
Since I'm eventually retrieving the key from AWS Secrets Manager I will have to treat it as a string and not a file on disk. I've tried using \n
newline in the hardcoded string key, but doesn't make any difference.
What am I missing?