コード例 #1
0
 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);
     }
 }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        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);
                }
            }
        }
コード例 #4
0
ファイル: SignatureWriter.cs プロジェクト: VahidN/PdfReport
 /// <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);
 }
コード例 #5
0
ファイル: SignatureWriter.cs プロジェクト: VahidN/PdfReport
        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);
                }
            }
        }
コード例 #6
0
ファイル: SignatureWriter.cs プロジェクト: VahidN/PdfReport
 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);
     }
 }
コード例 #7
0
ファイル: SignatureWriter.cs プロジェクト: VahidN/PdfReport
        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);
            }
        }
コード例 #8
0
ファイル: SignatureWriter.cs プロジェクト: VahidN/PdfReport
 /// <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);
 }
コード例 #9
0
 /// <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);
 }
コード例 #10
0
 /// <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);
 }