Open hermesalvesbr opened 2 years ago
Hey, @hermesalvesbr that's totally my bad, I was using the wrong type of date.
You can either update this file in your code or just pull the latest code from this repo.
Let me know if that worked for you.
Perfect, it's solve this problem. Thank you.
Successfully compiled 3 files with Babel (221ms).
/home/hermes/Projetos/vue/pdf_sign/node_modules/node-forge/lib/asn1.js:357
var error = new Error('Too few bytes to parse DER.');
^
Error: Too few bytes to parse DER.
at _checkBufferLength (/home/hermes/Projetos/vue/pdf_sign/node_modules/node-forge/lib/asn1.js:357:17)
at _getValueLength (/home/hermes/Projetos/vue/pdf_sign/node_modules/node-forge/lib/asn1.js:395:5)
at _fromDer (/home/hermes/Projetos/vue/pdf_sign/node_modules/node-forge/lib/asn1.js:498:16)
at _fromDer (/home/hermes/Projetos/vue/pdf_sign/node_modules/node-forge/lib/asn1.js:541:20)
at Object.asn1.fromDer (/home/hermes/Projetos/vue/pdf_sign/node_modules/node-forge/lib/asn1.js:458:15)
at _decodeSafeContents (/home/hermes/Projetos/vue/pdf_sign/node_modules/node-forge/lib/pkcs12.js:629:23)
at _decodeAuthenticatedSafe (/home/hermes/Projetos/vue/pdf_sign/node_modules/node-forge/lib/pkcs12.js:564:20)
at Object.p12.pkcs12FromAsn1 (/home/hermes/Projetos/vue/pdf_sign/node_modules/node-forge/lib/pkcs12.js:479:3)
at SignPdf.sign (/home/hermes/Projetos/vue/pdf_sign/node_modules/node-signpdf/dist/signpdf.js:104:43)
at SignPDF.signPDF (/home/hermes/Projetos/vue/pdf_sign/dist/SignPDF.js:30:35) {
available: 2065,
remaining: 95,
requested: 105
}
error Command failed with exit code 1.
Now a error is about the byte place into pdf.
Hmmm, I haven't seen this issue before. I came across this answer after some Googling.
https://stackoverflow.com/a/26045255/2395062
Looks like it's related to node-forge. If you're not comfortable sharing your certificate and pdf you might have to get your hands dirty and try a few of these options in the source code.
Otherwise you can email me those resources and I can try it out myself.
Thanks, i guess i need to change this line:
const DEFAULT_BYTE_RANGE_PLACEHOLDER = '**********';
I sent by email my code.
Kind regards
I haven't yet received an email. Could you send it again, please?
I sent again, from hermes.alves@araripina.com.br
Thanks, I've got it now.
I've had a look at your files and I think it might have something to do with your certificate.
How did you create it? Or was it purchased?
It's purchased, with this code works:
const signer = require('node-signpdf').default;
const fs = require('fs');
const { plainAddPlaceholder } = require('node-signpdf/dist/helpers');
const filename = '/home/hermes/Projetos/vue/signpdf/pdf/paraAssinar.pdf';
const cert = '/home/hermes/Projetos/vue/signpdf/pdf/softagon.pfx';
var output = plainAddPlaceholder({
pdfBuffer: fs.readFileSync(filename),
reason: 'Minha Assinatura',
signatureLength: 8192
});
const signedPdf = signer.sign(output, fs.readFileSync(cert), { passphrase: '*37us82', asn1StrictParsing: true });
fs.writeFileSync(__dirname + '/last.pdf', signedPdf);
fs.writeFileSync(filename, signedPdf);
console.log(`Successfully signed ${filename}`);
I attached the signed last.pdf last.pdf
That's odd. I guess I could look into how plainAddPlaceholder
works.
I've noticed your signature length is 8192 and my code has it as 3322. Maybe this is a limitation of pdf-lib.js 🤷
Thanks for your youtube channel!
I'm trying to run your code, but didn´t work. I have tried to update the dependencies too, and not working here.
Did you know why?