I'm trying to decrypt a file encrypted with GnuPG 2.2.28 using the Node.js package openPGP, but I can't even seem to load the private key to start with and I get the following error:
{
"errorType": "Runtime.UnhandledPromiseRejection",
"errorMessage": "Error: Misformed armored text",
"trace": [
"Runtime.UnhandledPromiseRejection: Error: Misformed armored text",
" at process.<anonymous> (/var/runtime/index.js:35:15)",
" at process.emit (events.js:314:20)",
" at process.EventEmitter.emit (domain.js:483:12)",
" at processPromiseRejections (internal/process/promises.js:209:33)",
" at processTicksAndRejections (internal/process/task_queues.js:98:32)"
]
}
In my code it looks like I've provided the armored key correctly, using backticks to enclose the key:
const openpgp = require('openpgp');
async() => {
try {
const passphrase = `changeit`;
const priv_key = `-----BEGIN PGP PRIVATE KEY BLOCK-----
lQPGBGEcehABCAC2/ws+pKo/9DB2JgQI3IXUXtj666KfHiFF2GjfEY5FvWIqm7Cq
MneNHyp+HfgjI6L0C1UAhUtUZaHFpKYfCbKoXH4Odwvor8f1RaxA7/IdvY+JJdx2
2tv/ZJdAP35XXRp0XrHPQIyEnTlvWPTPNFKb3kRaEFJnJfbCGSfocSWq9mrPc1J3
...
-----END PGP PRIVATE KEY BLOCK-----`;
const privateKey = await openpgp.decryptKey({
privateKey: await openpgp.readPrivateKey({
armoredKey: priv_key
}),
passphrase
});
} catch (e) {
console.log("ERROR: Unexpected error in PGP decryption", e.stack);
}
//...
}
Has any one else encountered a similar problem?