PdfDocument.GetSignedSignatureFields

Gets the list of PdfSignatureField that are present in the document.

public List<PdfSignatureField> GetSignedSignatureFields()
Function GetSignedSignatureFields() As List(Of PdfSignatureField)

Returns

List<PdfSignatureField>

Returns a list of PdfSignatureField objects

Licensing Info

This method is a full DynamicPDF Core Suite feature. One of the following is required for non-evaluation usage:

Examples

Following example verifies the signature present in a document.
Module Example
    Sub SignVerify(sourcePdfFilePath as string)
	
		'Create a PdfDocument object using the source PDF that is being verified for signatures		
        Dim pdfDocument As PdfDocument = New PdfDocument(sourcePdfFilePath)
		
		'Get the list of PdfSignatureField from the pdf document
        Dim signedSignatures As List(Of PdfSignatureField) = pdfDocument.GetSignedSignatureFields()
		
		'Get the Document Security Store (DSS) that contains the security and signature validation related information
        Dim dss As SecurityStore = pdfDocument.GetSecurityStore()

		'Method that validates the first field in the signedSignatures
        ProcessPkcsSignatureContents(fileName, signedSignatures(0))
    End Sub

    Sub ProcessPkcsSignatureContents(fileName As String, pdfSignatureField As PdfSignatureField)
		
		'Get the content that is signed using the selected signature field
        Dim signatureContent As Byte() = pdfSignatureField.SignatureContent

		'Create a byte array to hold the data that is present in the signature range
        Dim dataToVerify As Byte() = New Byte(pdfSignatureField.Range(0).Length + pdfSignatureField.Range(1).Length) 
		
		'Get all the PDF file data that is being validated
        Dim fileData As Byte() = File.ReadAllBytes(fileName)
		
		'Load the dataToVerify from the PDF, using the range of the signature
        Array.Copy(fileData, dataToVerify, pdfSignatureField.Range(0).Length)
        Array.Copy(fileData, pdfSignatureField.Range(1).StartIndex, dataToVerify, pdfSignatureField.Range(0).Length, pdfSignatureField.Range(1).Length)
        
		'Create a ContentInfo object using the data to be verified
		Dim contentInfo As ContentInfo = New ContentInfo(dataToVerify)
		
		'Create a SignedCms object using contentInfo
        Dim signedCms As SignedCms = New SignedCms(contentInfo, True)
        
		'Decode the signature content
		signedCms.Decode(signatureContent)
        
		'Verify the signature. This method will throw an exception if the data is invalid for the given signature.
		signedCms.CheckSignature(False)
    End Sub
End Module
using ceTe.DynamicPDF.Merger;
using System;
using System.IO;
using System.Security.Cryptography.Pkcs;
          
class Examples
{
    public static void SignVerify(string sourcePdfFilePath)
    {
        // Create a PdfDocument object using the source PDF that is being verified for signatures
        PdfDocument pdfDocument = new PdfDocument(sourcePdfFilePath);

        // Get the list of PdfSignatureField from the pdf document
        var signedSignatures = pdfDocument.GetSignedSignatureFields();

        // Get the Document Security Store (DSS) that contains the security and signature validation related information
        var dss = pdfDocument.GetSecurityStore();

        // Method that validates the first field in the signedSignatures
        ProcessPkcsSignatureContents(sourcePdfFilePath, signedSignatures[0]);
    }

    private static void ProcessPkcsSignatureContents(string fileName, ceTe.DynamicPDF.Merger.Forms.PdfSignatureField pdfSignatureField)
    {
        // Get the content that is signed using the selected signature field
        byte[] signatureContent = pdfSignatureField.SignatureContent;

        // Create a byte array to hold the data that is present in the signature range
        byte[] dataToVerify = new byte[pdfSignatureField.Range[0].Length + pdfSignatureField.Range[1].Length];

        // Get all the PDF file data that is being validated
        byte[] fileData = File.ReadAllBytes(fileName);

        // Load the dataToVerify from the PDF, using the range of the signature
        Array.Copy(fileData, dataToVerify, pdfSignatureField.Range[0].Length);
        Array.Copy(fileData, pdfSignatureField.Range[1].StartIndex, dataToVerify, pdfSignatureField.Range[0].Length, pdfSignatureField.Range[1].Length);

        // Create a ContentInfo object using the data to be verified
        ContentInfo contentInfo = new ContentInfo(dataToVerify);

        // Create a SignedCms object using contentInfo
        SignedCms signedCms = new SignedCms(contentInfo, true);

        // Decode the signature content
        signedCms.Decode(signatureContent);

        // Verify the signature. This method will throw an exception if the data is invalid for the given signature.
        signedCms.CheckSignature(false);
    }
}

See Also

PdfDocument
ceTe.DynamicPDF.Merger

In this topic