Quick Start (MTOM): Removing password-based encryption using the web service API

The following C# code example removes password-based encryption from a PDF document named EncryptLoan.pdf. The master password value used to remove password-based encryption is PermissionPassword. The unsecured PDF document is saved as a PDF file named noEncryptionLoan.pdf. (See Removing Password Encryption.)

/** 
    * 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 RemovePasswordEncryption.ServiceReference1; 
 
namespace RemovePasswordEncryption 
{ 
       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 password-encrypted PDF document  
                   BLOB inDoc = new BLOB(); 
 
                   //Specify the password-encrypted PDF document 
                   string path = "C:\\Adobe\EncryptLoan.pdf"; 
                   FileStream fs = new FileStream(path, FileMode.Open); 
 
                   //Get the file stream length and create a byte array   
                   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; 
 
                   //Remove password-based encryption from the PDF document 
                   BLOB outDoc = encryptClient.removePDFPasswordSecurity(inDoc, "PermissionPassword"); 
 
                   //Populate a byte array with BLOB data 
                   byte[] outByteArray = outDoc.MTOM; 
 
                   //Create a new file that represents the unsecured PDF document 
                   string FILE_NAME = "C:\\Adobe\noEncryptionLoan.pdf"; 
                   FileStream fs2 = new FileStream(FILE_NAME, FileMode.OpenOrCreate); 
 
                   //Create a BinaryWriter object 
                   BinaryWriter w = new BinaryWriter(fs2); 
                   w.Write(outByteArray); 
                   w.Close(); 
                   fs2.Close(); 
               } 
 
               catch (Exception ee) 
               { 
                   Console.WriteLine(ee.Message); 
               } 
           } 
       } 
}