node-signpdf
node-signpdf copied to clipboard
Signature is invalid
Describe the bug and the expected behaviour I'm trying to sign a PDF with an external signature and my signature is invalid. When I read it with Adobe I get the following error: "There are errors in the formatting or information contained in this signature".
Is it a bug in signing or in the helpers? It's a bug in signing.
To Reproduce I used the following code to place the external signature directly on the PDF.
const raw = base64ToArrayBuffer(externalSignature);
if (raw.length * 2 > placeholderLength) {
throw new _SignPdfError.default(`Signature exceeds placeholder length: ${raw.length * 2} > ${placeholderLength}`, _SignPdfError.default.TYPE_INPUT);
}
let signature = Buffer.from(raw, 'binary').toString('hex');
this.lastSignature = signature; // Pad the signature with zeroes so the it is the same length as the placeholder
signature += Buffer.from(String.fromCharCode(0).repeat(placeholderLength / 2 - raw.length)).toString('hex');
pdf = Buffer.concat([pdf.slice(0, byteRange[1]), Buffer.from(`<${signature}>`), pdf.slice(byteRange[1])]);
return pdf;
Attached I send the source PDF and the failed PDF. fatura.pdf fatura1662389260774.pdf