public virtual void SignEncryptedDoc01() { String fileName = "encrypted.pdf"; String src = sourceFolder + fileName; String dest = destinationFolder + "signed_" + fileName; String fieldName = "Signature1"; byte[] ownerPass = "******".GetBytes(); PdfReader reader = new PdfReader(src, new ReaderProperties().SetPassword(ownerPass)); PdfSigner signer = new PdfSigner(reader, new FileStream(dest, FileMode.Create), true); // Creating the appearance PdfSignatureAppearance appearance = signer.GetSignatureAppearance().SetReason("Test1").SetLocation("TestCity" ); signer.SetFieldName(fieldName); // Creating the signature IExternalSignature pks = new PrivateKeySignature(pk, DigestAlgorithms.SHA256); signer.SignDetached(pks, chain, null, null, null, 0, PdfSigner.CryptoStandard.CADES); LtvVerifier verifier = new LtvVerifier(new PdfDocument(new PdfReader(dest, new ReaderProperties().SetPassword (ownerPass)))); verifier.SetVerifyRootCertificate(false); verifier.Verify(null); }
public virtual void ValidLtvDocTest02() { String ltvTsFileName = sourceFolder + "ltvDoc.pdf"; LtvVerifier verifier = new LtvVerifier(new PdfDocument(new PdfReader(ltvTsFileName))); verifier.SetCertificateOption(LtvVerification.CertificateOption.WHOLE_CHAIN); verifier.SetRootStore(Pkcs12FileHelper.InitStore(certsSrc + "rootStore.p12", password)); IList <VerificationOK> verificationMessages = verifier.Verify(null); NUnit.Framework.Assert.AreEqual(7, verificationMessages.Count); }
public void Validate(PdfReader reader) { List <X509Certificate> certificates = new List <X509Certificate>(); X509CertificateParser parser = new X509CertificateParser(); FileStream file = new FileStream(ADOBE, FileMode.Open); certificates.Add(parser.ReadCertificate(file)); MyVerifier custom = new MyVerifier(null); LtvVerifier data = new LtvVerifier(reader); data.Certificates = certificates; data.CertificateOption = LtvVerification.CertificateOption.WHOLE_CHAIN; data.Verifier = custom; data.OnlineCheckingAllowed = false; data.VerifyRootCertificate = false; List <VerificationOK> list = new List <VerificationOK>(); try { data.Verify(list); } catch (GeneralSecurityException e) { Console.WriteLine(e.ToString()); } Console.WriteLine(); if (list.Count == 0) { Console.WriteLine("The document can't be verified"); } foreach (VerificationOK v in list) { Console.WriteLine(v.ToString()); } file.Close(); }