private void addSignature(Stream inputPdfStream, Stream outputPdfStream, PfxData pfxData) { using (var stamper = PdfStamper.CreateSignature(new CustomPdfReader(inputPdfStream, pfxData.X509PrivateKeys[0], pfxData.PublicKey), outputPdfStream, '\0', null, SignatureData.CertificateFile.AppendSignature)) { tryAddSignature(stamper); } }
private void addSignature(Stream inputPdfStream, PfxData pfxData) { byte[] buffer; using (var outputPdfStream = new MemoryStream()) { using (var stamper = PdfStamper.CreateSignature(new CustomPdfReader(inputPdfStream, pfxData.X509PrivateKeys[0], pfxData.PublicKey), outputPdfStream, '\0', null, SignatureData.CertificateFile.AppendSignature)) { tryAddSignature(stamper); } buffer = outputPdfStream.GetBuffer(); } inputPdfStream.Position = 0; inputPdfStream.SetLength(0); using (var signedStream = new MemoryStream(buffer)) { signedStream.WriteTo(inputPdfStream); } }
private void addSignature(string inputPdfPath, string outputPdfPath, PfxData pfxData) { if (string.IsNullOrEmpty(inputPdfPath) || !File.Exists(inputPdfPath)) { throw new FileNotFoundException("Please specify a valid InputPdfPath"); } if (string.IsNullOrEmpty(outputPdfPath) || !File.Exists(outputPdfPath)) { throw new FileNotFoundException("Please specify a valid OutputPdfPath"); } using (var stream = new FileStream(outputPdfPath, FileMode.Create, FileAccess.Write)) { using (var stamper = PdfStamper.CreateSignature(new PdfReader(inputPdfPath, pfxData.X509PrivateKeys[0], pfxData.PublicKey), stream, '\0', null, SignatureData.CertificateFile.AppendSignature)) { tryAddSignature(stamper); } } }
/// <summary> /// Applies a digital signature to a document /// </summary> /// <param name="inputPdfStream">Input/Output pdf file's stream</param> /// <param name="pfxData">The Personal Information Exchange File Info which is used to encrypt the file.</param> public void SignPdf(Stream inputPdfStream, PfxData pfxData) { validateInputs(); readCertificate(); addSignature(inputPdfStream, pfxData); }
private void addSignature(string inputPdfPath, string outputPdfPath, PfxData pfxData) { if (string.IsNullOrEmpty(inputPdfPath) || !File.Exists(inputPdfPath)) throw new FileNotFoundException("Please specify a valid InputPdfPath"); if (string.IsNullOrEmpty(outputPdfPath) || !File.Exists(outputPdfPath)) throw new FileNotFoundException("Please specify a valid OutputPdfPath"); using (var stream = new FileStream(outputPdfPath, FileMode.Create, FileAccess.Write)) { using (var stamper = PdfStamper.CreateSignature(new PdfReader(inputPdfPath, pfxData.X509PrivateKeys[0], pfxData.PublicKey), stream, '\0', null, SignatureData.CertificateFile.AppendSignature)) { tryAddSignature(stamper); } } }
/// <summary> /// Applies a digital signature to a document /// </summary> /// <param name="inputPdfPath">Input pdf file's path</param> /// <param name="outputPdfPath">Output/Signed pdf file's path</param> /// <param name="pfxData">The Personal Information Exchange File Info which is used to encrypt the file.</param> public void SignPdf(string inputPdfPath, string outputPdfPath, PfxData pfxData) { validateInputs(); readCertificate(); addSignature(inputPdfPath, outputPdfPath, pfxData); }