public virtual void LtvEnabledTest01() { String tsaCertFileName = certsSrc + "tsCertRsa.p12"; String caCertFileName = certsSrc + "rootRsa.p12"; String srcFileName = sourceFolder + "signedDoc.pdf"; String ltvFileName = destinationFolder + "ltvEnabledTest01.pdf"; String ltvTsFileName = destinationFolder + "ltvEnabledTsTest01.pdf"; X509Certificate[] tsaChain = Pkcs12FileHelper.ReadFirstChain(tsaCertFileName, password); ICipherParameters tsaPrivateKey = Pkcs12FileHelper.ReadFirstKey(tsaCertFileName, password, password); X509Certificate caCert = (X509Certificate)Pkcs12FileHelper.ReadFirstChain(caCertFileName, password)[0]; ICipherParameters caPrivateKey = Pkcs12FileHelper.ReadFirstKey(caCertFileName, password, password); TestTsaClient testTsa = new TestTsaClient(JavaUtil.ArraysAsList(tsaChain), tsaPrivateKey); TestOcspClient testOcspClient = new TestOcspClient().AddBuilderForCertIssuer(caCert, caPrivateKey); TestCrlClient testCrlClient = new TestCrlClient(caCert, caPrivateKey); PdfDocument document = new PdfDocument(new PdfReader(srcFileName), new PdfWriter(ltvFileName), new StampingProperties ().UseAppendMode()); LtvVerification ltvVerification = new LtvVerification(document); ltvVerification.AddVerification("Signature1", testOcspClient, testCrlClient, LtvVerification.CertificateOption .SIGNING_CERTIFICATE, LtvVerification.Level.OCSP_CRL, LtvVerification.CertificateInclusion.YES); ltvVerification.Merge(); document.Close(); PdfSigner signer = new PdfSigner(new PdfReader(ltvFileName), new FileStream(ltvTsFileName, FileMode.Create ), new StampingProperties().UseAppendMode()); signer.Timestamp(testTsa, "timestampSig1"); BasicCheckLtvDoc("ltvEnabledTsTest01.pdf", "timestampSig1"); }
private void AdicionarLtv(string pdfPrimeiraAssinatura, SingInfo singInfo) { var inicioCarimbo = DateTime.Now; var stamping = new StampingProperties(); stamping.UseAppendMode(); PdfDocument pdfDoc = new PdfDocument( new PdfReader(pdfPrimeiraAssinatura), new PdfWriter(singInfo.TargetPdf)); LtvVerification v = new LtvVerification(pdfDoc); SignatureUtil signatureUtil = new SignatureUtil(pdfDoc); var names = signatureUtil.GetSignatureNames(); var sigName = names[names.Count - 1]; var pkcs7 = signatureUtil.VerifySignature(sigName); if (pkcs7.IsTsp()) { v.AddVerification( sigName, this.ocspClient, new CrlClientOnline(this.cadeiaTempo.ToArray()), LtvVerification.CertificateOption.SIGNING_CERTIFICATE, LtvVerification.Level.OCSP_CRL, LtvVerification.CertificateInclusion.YES); } else { foreach (var name in names) { v.AddVerification( name, this.ocspClient, new CrlClientOnline(this.cadeiaTempo.ToArray()), LtvVerification.CertificateOption.WHOLE_CHAIN, LtvVerification.Level.OCSP_CRL, LtvVerification.CertificateInclusion.NO); } } pdfDoc.Close(); Console.WriteLine("Aplicando timestamp........"); PdfReader r = new PdfReader(pdfPrimeiraAssinatura); PdfSigner pdfSigner = new PdfSigner(r, new FileStream(singInfo.TargetPdf, FileMode.Create), stamping); pdfSigner.Timestamp(this.tsaClient, null); var fimCarimbo = DateTime.Now; var tempoCarimbo = fimCarimbo.Subtract(inicioCarimbo); Console.WriteLine("Tempo Carimbo: {0}ms", tempoCarimbo.TotalMilliseconds); }
public virtual void PadesSignatureLevelLTATest01() { String outFileName = destinationFolder + "padesSignatureLevelLTATest01.pdf"; String srcFileName = sourceFolder + "signedPAdES-LT.pdf"; String tsaCertFileName = certsSrc + "tsCertRsa.p12"; X509Certificate[] tsaChain = Pkcs12FileHelper.ReadFirstChain(tsaCertFileName, password); ICipherParameters tsaPrivateKey = Pkcs12FileHelper.ReadFirstKey(tsaCertFileName, password, password); PdfSigner signer = new PdfSigner(new PdfReader(srcFileName), new FileStream(outFileName, FileMode.Create), new StampingProperties().UseAppendMode()); TestTsaClient testTsa = new TestTsaClient(JavaUtil.ArraysAsList(tsaChain), tsaPrivateKey); signer.Timestamp(testTsa, "timestampSig1"); PadesSigTest.BasicCheckSignedDoc(destinationFolder + "padesSignatureLevelLTATest01.pdf", "timestampSig1"); }
public virtual void TimestampTest01() { String tsaCertFileName = certsSrc + "tsCertRsa.p12"; String srcFileName = sourceFolder + "helloWorldDoc.pdf"; String outFileName = destinationFolder + "timestampTest01.pdf"; X509Certificate[] tsaChain = Pkcs12FileHelper.ReadFirstChain(tsaCertFileName, password); ICipherParameters tsaPrivateKey = Pkcs12FileHelper.ReadFirstKey(tsaCertFileName, password, password); PdfSigner signer = new PdfSigner(new PdfReader(srcFileName), new FileStream(outFileName, FileMode.Create), false); TestTsaClient testTsa = new TestTsaClient(iText.IO.Util.JavaUtil.ArraysAsList(tsaChain), tsaPrivateKey); signer.Timestamp(testTsa, "timestampSig1"); PadesSigTest.BasicCheckSignedDoc(destinationFolder + "timestampTest01.pdf", "timestampSig1"); }