Quick Start (MTOM): Determining encryption type using the web service API

The following C# code example determines the type of encryption that is protecting a PDF document named EncryptLoan.pdf. (See Determining Encryption Type.)

/** 
    * 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 DetermineEncryptionType.ServiceReference1; 
 
namespace DetermineEncryptionType 
{ 
       class Program 
       { 
           static void Main(string[] args) 
           { 
               try 
               { 
                   //Create a EncryptionServiceClient object 
                   EncryptionServiceClient encryptClient = new EncryptionServiceClient(); 
                   encryptClient.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://hiro-xp:8080/soap/services/EncryptionService?blob=mtom"); 
 
                   //Enable BASIC HTTP authentication 
                   BasicHttpBinding b = (BasicHttpBinding)encryptClient.Endpoint.Binding; 
                   b.MessageEncoding = WSMessageEncoding.Mtom; 
                   encryptClient.ClientCredentials.UserName.UserName = "administrator"; 
                   encryptClient.ClientCredentials.UserName.Password = "password"; 
                   b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; 
                   b.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; 
 
                   //Create a BLOB object to store the PDF document  
                   BLOB inDoc = new BLOB(); 
 
                   //Specify the PDF document  
                   string path = "C:\\Adobe\EncryptLoan.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; 
 
                   //Determine the encryption type 
                   EncryptionTypeResult encryptTypeResult = encryptClient.getPDFEncryption(inDoc); 
 
                   if (encryptTypeResult.encryptionType == EncryptionType.PASSWORD) 
                       Console.WriteLine("The PDF document is protected with password-based encryption"); 
                   else if (encryptTypeResult.encryptionType == EncryptionType.POLICY_SERVER) 
                       Console.WriteLine("The PDF document is protected with policy"); 
                   else if (encryptTypeResult.encryptionType == EncryptionType.CERTIFICATE) 
                       Console.WriteLine("The PDF document is protected with certificate-based encryption"); 
                   else if (encryptTypeResult.encryptionType == EncryptionType.OTHER) 
                       Console.WriteLine("The PDF document is protected with another type of encryption"); 
                   else if (encryptTypeResult.encryptionType == EncryptionType.NONE) 
                       Console.WriteLine("The PDF document is not protected."); 
               } 
               catch (Exception ee) 
               { 
                   Console.WriteLine(ee.Message); 
               } 
           } 
       } 
}