Back to Devexpress

PdfPkcs7Signature Class

officefileapi-devexpress-dot-pdf-dot-pdfpkcs7signature.md

latest3.9 KB
Original Source

PdfPkcs7Signature Class

Contains information about the PKCS#7 signature and methods used to verify it.

Namespace : DevExpress.Pdf

Assembly : DevExpress.Pdf.v25.2.Core.dll

NuGet Package : DevExpress.Pdf.Core

Declaration

csharp
public class PdfPkcs7Signature :
    PdfSignatureBase
vb
Public Class PdfPkcs7Signature
    Inherits PdfSignatureBase

The following members return PdfPkcs7Signature objects:

Remarks

The code snippet below obtains the PKCS#7 signature from a PDF document saved to the stream. Once the signature is obtained, the code checks attributes such as the time of signing, the signer’s identity, and authenticity of the signature.

csharp
using DevExpress.Pdf;
// ...
using(PdfDocumentSigner documentSigner = new PdfDocumentSigner(stream))
    // Obtain the PKCS#7 signature from the list of `PdfSignatureInfo` objects.
    foreach(var signature in documentSigner.GetSignatureInfo()) {
        var pkcs7 = documentSigner.GetPdfPkcs7Signature(signature.FieldName);
       // Obtain the PKCS#7 signature certificate.
        var certificate = pkcs7.GetSignatureCertificate();
       // Check wheter the signature is valid.
        bool isValid = pkcs7.VerifySignature();
        // Verify the signature certificate info.
        string issuerName = certificate.IssuerName.Name;
        bool isCertificateValid = certificate.Verify();
        // Verify the time of signing.
        var timeStamp = pkcs7.GetTimeStampDate();
        bool isTimeStampValid = pkcs7.VerifyTimeStamp();
    }
vb
Imports DevExpress.Pdf
' ...
Using documentSigner As New PdfDocumentSigner(stream)
    For Each signature In documentSigner.GetSignatureInfo()
       ' Obtain the PKCS#7 signature.
        Dim pkcs7 = documentSigner.GetPdfPkcs7Signature(signature.FieldName)
       ' Obtain the PKCS#7 signature certificate.
        Dim certificate = pkcs7.GetSignatureCertificate()
       ' Check wheter the signature is valid.
        Dim isValid As Boolean = pkcs7.VerifySignature()
        ' Verify the signature certificate info.
        Dim issuerName As String = certificate.IssuerName.Name
        Dim isCertificateValid As Boolean = certificate.Verify()
        ' Verify the time of signing.
        Dim timeStamp = pkcs7.GetTimeStampDate()
        Dim isTimeStampValid As Boolean = pkcs7.VerifyTimeStamp()
    Next signature
End Using

Call the PdfPkcs7Signature.CheckCertificateRevocation method to obtain information about signature certificate revocation based on Online Certificate Status Protocol (OCSP) and Certificate Revocation List (CRL) responses. Call the PdfDocumentSigner.VerifyLtv method to obtain Long Term Validation (LTV) records about the state of the signature certificate.

Inheritance

Object PdfSignatureBase PdfPkcs7Signature

See Also

PdfPkcs7Signature Members

How to: Validate a PDF Document Signature

DevExpress.Pdf Namespace