Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Illegal values in ByteRange array/ Signature has not yet been verified #251

Open
stefanmiodrag opened this issue Apr 21, 2024 · 0 comments

Comments

@stefanmiodrag
Copy link

stefanmiodrag commented Apr 21, 2024

When I run pdfsig <document_path> I get the following error:

Syntax Error (0): Illegal values in ByteRange array
  - Signer Certificate Common Name: (null)
  - Signer full Distinguished Name: (null)
  - Signing Time: Apr 21 2024 19:09:32
  - Signing Hash Algorithm: unknown
  - Signature Type: adbe.pkcs7.detached
  - Signed Ranges: [0 - 25497], [41883 - 43123]
  - Not total document signed
  - Signature Validation: Signature has not yet been verified.

My code looks like this:

export async function POST(request: Request) {
    try {
        const { pdfBase64 } = await request.json();
        const pdfBuffer = Buffer.from(pdfBase64, "base64");

        // certificate.p12 is the certificate that is going to be used to sign
        const certificatePath = join(process.cwd(), "/public/client-identity.p12");
        const certificateBuffer = fs.readFileSync(certificatePath);

        const signer = new P12Signer(certificateBuffer);

        const pdfWithPlaceholder = plainAddPlaceholder({
            pdfBuffer,
            reason: "The user is decalaring consent.",
            contactInfo: "[email protected]",
            name: "John Doe",
            location: "Free Text Str., Free World",
        });

        // pdfWithPlaceholder is now a modified buffer that is ready to be signed.
        const signedPdf = await signpdf.sign(pdfWithPlaceholder, signer);
        const signedPdfBase64 = signedPdf.toString('base64');
        console.log(signedPdf);
        return NextResponse.json({ signedPdfBase64 }, { status: 200 });
    } catch (error) {
        console.error(error);
        return NextResponse.json(error, { status: 500 });
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant