Answer the question
In order to leave comments, you need to log in
Where to place digital signature in PDF (openpgp.js)?
Hello!
I implement a digital signature of pdf files using openpgp.js.
The question is - how / where to place the signature so that the file itself is not damaged?
If done straight:
const file = fs.readFileSync('./testdoc.pdf', 'utf-8');
let privkey = fs.readFileSync('./private1.key', 'utf-8'); //encrypted private key
let passphrase = 'secret'; //what the privKey is encrypted with
const privKeyObj = openpgp.key.readArmored(privkey).keys[0];
privKeyObj.decrypt(passphrase);
openpgp.sign({
data: file, // input as String (or Uint8Array)
privateKeys: privKeyObj, // for signing
//detached: true,
})
.then(signed => {
//console.log(signed.signature);
fs.writeFileSync('./testdoc.pdf', signed.data);
});
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
%PDF-1.3
%����
4 0 obj
<<
/Type /Page
var message = openpgp.message.readSignedContent(file, sig); //file - исходный файл, без подписи, sig - файл с сигнатурой, в кодировке utf-8
var result = message.verify(openpgp.key.readArmored(pubkey).keys); // result.valid=false всегда
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question