public virtual void OpenEncryptedDocWithWrongCertificateAndPrivateKey() { NUnit.Framework.Assert.That(() => { PdfReader reader = new PdfReader(sourceFolder + "encryptedWithCertificateAes128.pdf", new ReaderProperties ().SetPublicKeySecurityParams(GetPublicCertificate(sourceFolder + "wrong.cer"), CryptoUtil.ReadPrivateKeyFromPkcs12KeyStore (new FileStream(sourceFolder + "wrong.p12", FileMode.Open, FileAccess.Read), "demo", "password".ToCharArray ()))); PdfDocument doc = new PdfDocument(reader); doc.Close(); } , NUnit.Framework.Throws.InstanceOf<PdfException>().With.Message.EqualTo(PdfException.BadCertificateAndKey)) ; }
/// <exception cref="System.IO.IOException"/> /// <exception cref="Java.Security.Cert.CertificateException"/> public virtual X509Certificate GetPublicCertificate(String path) { FileStream @is = new FileStream(path, FileMode.Open, FileAccess.Read); return CryptoUtil.ReadPublicCertificate(@is); }