I have generated key pair using gpg4win-3.1.2.
I have both public and private key with pass-phrase.
I created a csv file and encrypted it using kleopatra tool.
I am able to decrypt the file using node gpg library but it uses binary to decrypt.
can we use openpgp to decrypt the same file?
You should be able to, yes. Does it not work?
Yes. Its not working.
Following code ->
const path = require('path');
const fs = require('fs');
const openpgp = require('openpgp');
const privkey = fs.readFileSync(path.join(__dirname, 'private.asc'), 'utf8');
const pubkey = fs.readFileSync(path.join(__dirname, 'public.asc'), 'utf8');
const encrypted = fs.readFileSync(path.join(__dirname, 'test.csv.gpg'),'utf8');
const passphrase = test;
const encryptDecryptFunction = async() => {
const privKeyObj = (await openpgp.key.readArmored(privkey)).keys[0]
await privKeyObj.decrypt(passphrase)
const options = {
message: await openpgp.message.readArmored(encrypted), // parse armored message
publicKeys: (await openpgp.key.readArmored(pubkey)).keys, // for verification (optional)
privateKeys: [privKeyObj] // for decryption
}
openpgp.decrypt(options).then(plaintext => {
console.log(plaintext.data)
return plaintext.data
}).catch(err => {
console.log(err);
})
}
encryptDecryptFunction();
Has error -> UnhandledPromiseRejectionWarning: Error: Misformed armored text
openpgp.message.readArmored parses armored message data, which is a string beginning with "-----BEGIN PGP MESSAGE-----".
To parse binary data into a message object, you will need to use openpgp.message.read instead.
Most helpful comment
openpgp.message.readArmoredparses armored message data, which is a string beginning with "-----BEGIN PGP MESSAGE-----".To parse binary data into a message object, you will need to use
openpgp.message.readinstead.