Я пытаюсь цифрово подписывать и проверять pdf-документы с помощью iTextsharp 5.3.3. . Подпись прикреплена правильно, но галочка не отображается. Любое предложение..
я использую приведенный ниже код для проверки подписи
PdfReader reader = new PdfReader(DestPdfFileName); AcroFields af = reader.AcroFields; var names = af.GetSignatureNames(); if (names.Count == 0) { throw new InvalidOperationException("No Signature present in pdf file."); } foreach (string name in names) { if (!af.SignatureCoversWholeDocument(name)) { throw new InvalidOperationException(string.Format("The signature: {0} does not covers the whole document.", name)); } PdfPKCS7 pk = af.VerifySignature(name); var cal = pk.SignDate; var pkc = pk.Certificates; pkc = pk.SignCertificateChain; // TimeStampToken ts = pk.TimeStampToken; cal = pk.SignDate; //if (ts != null) // cal = pk.TimeStampDate; //if (!pk.IsTsp && ts != null) //{ // bool impr = pk.VerifyTimestampImprint(); //} if (!pk.Verify()) { throw new InvalidOperationException("The signature could not be verified."); } //if (!pk.VerifyTimestampImprint()) //{ // //throw new InvalidOperationException("The signature timestamp could not be verified."); //} //var fails = CertificateVerification.VerifyCertificates(pkc, X509Certificate2Signature(cert, "SHA1"), null, cal); //// var fails2 = CertificateVerification.VerifyCertificate(pkc, null, cal); //if (fails != null) //{ // // throw new InvalidOperationException("The file is not signed using the specified key-pair."); //} }
Что я уже пробовал:
я использую приведенный ниже код для проверки подписи
PdfReader reader = new PdfReader(DestPdfFileName); AcroFields af = reader.AcroFields; var names = af.GetSignatureNames(); if (names.Count == 0) { throw new InvalidOperationException("No Signature present in pdf file."); } foreach (string name in names) { if (!af.SignatureCoversWholeDocument(name)) { throw new InvalidOperationException(string.Format("The signature: {0} does not covers the whole document.", name)); } PdfPKCS7 pk = af.VerifySignature(name); var cal = pk.SignDate; var pkc = pk.Certificates; pkc = pk.SignCertificateChain; // TimeStampToken ts = pk.TimeStampToken; cal = pk.SignDate; //if (ts != null) // cal = pk.TimeStampDate; //if (!pk.IsTsp && ts != null) //{ // bool impr = pk.VerifyTimestampImprint(); //} if (!pk.Verify()) { throw new InvalidOperationException("The signature could not be verified."); } //if (!pk.VerifyTimestampImprint()) //{ // //throw new InvalidOperationException("The signature timestamp could not be verified."); //} //var fails = CertificateVerification.VerifyCertificates(pkc, X509Certificate2Signature(cert, "SHA1"), null, cal); //// var fails2 = CertificateVerification.VerifyCertificate(pkc, null, cal); //if (fails != null) //{ // // throw new InvalidOperationException("The file is not signed using the specified key-pair."); //} }