Error during parsing. This message / key probably does not conform to a valid OpenPGP format. #1638
Unanswered
Naziatanveer
asked this question in
Q&A
Replies: 1 comment
-
Check that you're reading the file |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Encryption Code:
const openpgp = require("openpgp");
const fs = require("fs");
async function encryption() {
const dataToEncrypt = fs
.readFileSync("./dataToEncrypt.txt", "utf-8")
.toString();
const publicArmored = fs.readFileSync("./public.pem").toString();
const message = await openpgp.createMessage({ text: dataToEncrypt });
const publicKey = await openpgp.readKey({ armoredKey: publicArmored });
const encrypt = openpgp.encrypt({
message,
encryptionKeys: publicKey,
format: "binary",
});
return encrypt;
}
encryption().then((result) => {
console.log("Successful encryption");
fs.writeFileSync("binaryEncrypted.txt.pgp", result);
}).catch((error) => {
console.log("encryptions failed with error " + error.message);
});
Result : Encryption in binary format is generated
Decryption Code:
const openpgp = require("openpgp");
const fs = require("fs");
async function decryption() {
const dataToDecrypt = fs.readFileSync("./binaryEncrypted.txt.pgp", "ascii");
const privateArmored = fs.readFileSync("./private.pem").toString();
const privateKey = await openpgp.readKey({ armoredKey: privateArmored });
const unitArray = new Uint8Array(dataToDecrypt);
const message = await openpgp.readMessage({ binaryMessage: unitArray });
const decrypt = openpgp.decrypt({
message,
decryptionKeys: privateKey,
});
return decrypt;
}
decryption()then((result) => {
console.log("Successful Decryption");
fs.writeFileSync("binaryDecrypted.txt.pgp", result);
}).catch((error) => {
console.log("encryptions failed with error " + error.message);
});
Result: Error during parsing. This message / key probably does not conform to a valid OpenPGP format.
Can someone please help me why decryption is not working as expected ?
Beta Was this translation helpful? Give feedback.
All reactions