fix: support cert file encodings

This commit is contained in:
Mythie
2023-05-28 00:39:07 +10:00
parent 0881abdee4
commit 17d51354d7
2 changed files with 5 additions and 2 deletions

View File

@ -19,6 +19,7 @@ NEXTAUTH_URL='http://localhost:3000'
# SIGNING
CERT_FILE_PATH=
CERT_PASSPHRASE=
CERT_FILE_ENCODING=
# MAIL (NODEMAILER)
# SENDGRID

View File

@ -1,7 +1,7 @@
import { PDFDocument, PDFHexString, PDFName, PDFNumber, PDFString } from "pdf-lib";
const fs = require("fs");
import fs from "fs";
// Local copy of Node SignPDF because https://github.com/vbuch/node-signpdf/pull/187 was not published in NPM yet. Can be switched to npm packge.
const signer = require("./node-signpdf/dist/signpdf");
@ -9,7 +9,9 @@ export const addDigitalSignature = async (documentAsBase64: string): Promise<str
// Custom code to add Byterange to PDF
const PDFArrayCustom = require("./PDFArrayCustom");
const pdfBuffer = Buffer.from(documentAsBase64, "base64");
const p12Buffer = fs.readFileSync(process.env.CERT_FILE_PATH || "ressources/cert.p12");
const p12Buffer = fs.readFileSync(process.env.CERT_FILE_PATH || "ressources/certificate.p12", {
encoding: (process.env.CERT_FILE_ENCODING as BufferEncoding) || null,
});
const SIGNATURE_LENGTH = 12000;
const pdfDoc = await PDFDocument.load(pdfBuffer);