Quick Start (MTOM): Verifying a digital signature using the web service API

The following C# code example verifies a digital signature that is located in a signed PDF document that is based on a PDF file named LoanSigned.pdf. (See Verifying Digital Signatures.)

/** 
    * Ensure that you create a .NET project that uses  
    * MS Visual Studio 2008 and version 3.5 of the .NET 
    * framework. This is required to invoke a  
    * LiveCycle service using MTOM. 
    *      
    * For information, see "Invoking LiveCycle using MTOM" in Programming with LiveCycle   
    */ 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.ServiceModel; 
using System.IO; 
using VerifySignature.ServiceReference1; 
 
namespace VerifySignature 
{ 
       class Program 
       { 
           static void Main(string[] args) 
           { 
               try 
               { 
                   //Create a SignatureServiceClient object 
                   SignatureServiceClient sigClient = new SignatureServiceClient(); 
                   sigClient.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://hiro-xp:8080/soap/services/SignatureService?blob=mtom"); 
 
                   //Enable BASIC HTTP authentication 
                   BasicHttpBinding b = (BasicHttpBinding)sigClient.Endpoint.Binding; 
                   b.MessageEncoding = WSMessageEncoding.Mtom; 
                   sigClient.ClientCredentials.UserName.UserName = "administrator"; 
                   sigClient.ClientCredentials.UserName.Password = "password"; 
                   b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; 
                   b.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; 
                   b.MaxReceivedMessageSize = 2000000; 
                   b.MaxBufferSize = 2000000; 
                   b.ReaderQuotas.MaxArrayLength = 2000000; 
 
                   //Create a BLOB instance to store a PDF document 
                   BLOB inDoc = new BLOB(); 
 
                   //Specify a PDF document that contains the signature to verify 
                   string path = "C:\\Adobe\LoanSigned.pdf"; 
                   FileStream fs = new FileStream(path, FileMode.Open); 
 
                   //Get the length of the file stream  
                   int len = (int)fs.Length; 
                   byte[] ByteArray = new byte[len]; 
 
                   //Populate the byte array with the contents of the FileStream object 
                   fs.Read(ByteArray, 0, len); 
                   inDoc.MTOM = ByteArray; 
 
                   //Specify the name of the Signature field 
                   string fieldName = "SignatureField1"; 
 
                   //Create a PKIOptions object that contains PKI run-time options 
                   PKIOptions pkiOptions = new PKIOptions(); 
                   pkiOptions.verificationTime = VerificationTime.CURRENT_TIME; 
                   pkiOptions.revocationCheckStyle = RevocationCheckStyle.BestEffort; 
 
                   //Verify the digital signature 
                   PDFSignatureVerificationInfo signInfo = sigClient.verify2( 
                    inDoc, 
                    fieldName, 
                    pkiOptions, 
                    null); 
 
                   //Get the Signature Status 
                   SignatureStatus? sigStatus = signInfo.status; 
                   String myStatus = ""; 
 
                   if (sigStatus == SignatureStatus.DynamicFormSignatureUnknown) 
                       myStatus = "The signatures located in the dynamic PDF form are unknown"; 
                   else if (sigStatus == SignatureStatus.DocumentSignatureUnknown) 
                       myStatus = "The signatures located in the PDF document are unknown"; 
                   else if (sigStatus == SignatureStatus.CertifiedDynamicFormSignatureTamper) 
                       myStatus = "The signatures located in a certified PDF form are valid"; 
                   else if (sigStatus == SignatureStatus.SignedDynamicFormSignatureTamper) 
                       myStatus = "The signatures located in a signed dynamic PDF form are valid"; 
                   else if (sigStatus == SignatureStatus.CertifiedDocumentSignatureTamper) 
                       myStatus = "The signatures located in a certified PDF document are valid"; 
                   else if (sigStatus == SignatureStatus.SignedDocumentSignatureTamper) 
                       myStatus = "The signatures located in a signed PDF document are valid"; 
                   else if (sigStatus == SignatureStatus.SignatureFormatError) 
                       myStatus = "The format of a signature in a signed document is invalid"; 
                   else if (sigStatus == SignatureStatus.DynamicFormSigNoChanges) 
                       myStatus = "No changes were made to the signed dynamic PDF form"; 
                   else if (sigStatus == SignatureStatus.DocumentSigNoChanges) 
                       myStatus = "No changes were made to the signed PDF document"; 
                   else if (sigStatus == SignatureStatus.DynamicFormCertificationSigNoChanges) 
                       myStatus = "No changes were made to the certified dynamic PDF form"; 
                   else if (sigStatus == SignatureStatus.DocumentCertificationSigNoChanges) 
                       myStatus = "No changes were made to the certified PDF document"; 
                   else if (sigStatus == SignatureStatus.DocSigWithChanges) 
                       myStatus = "There were changes to a signed PDF document"; 
                   else if (sigStatus == SignatureStatus.CertificationSigWithChanges) 
                       myStatus = "There were changes made to the PDF document."; 
 
                   //Get the signature type 
                   SignatureType sigType = signInfo.signatureType; 
                   String myType = ""; 
                   if (sigType.type == PDFSignatureType.AUTHORSIG) 
                       myType = "Certification"; 
                   else if (sigType.type == PDFSignatureType.RECIPIENTSIG) 
                       myType = "Recipient"; 
 
                   //Get the identity of the signer 
                   IdentityInformation signerId = signInfo.signer; 
                   String signerMsg = ""; 
 
                   if (signerId.status == IdentityStatus.UNKNOWN) 
                       signerMsg = "Identity Unknown"; 
                   else if (signerId.status == IdentityStatus.TRUSTED) 
                       signerMsg = "Identity Trusted"; 
                   else if (signerId.status == IdentityStatus.NOTTRUSTED) 
                       signerMsg = "Identity Not Trusted"; 
 
                   Console.Write("The status of the signature is: " + myStatus + ". The signer identity is " + signerMsg + ". The signature type is " + myType + "."); 
 
               } 
               catch (Exception ee) 
               { 
                   Console.WriteLine(ee.Message); 
               } 
           } 
       } 
}