The following C# code example removes certificate-based
encryption from a PDF document named EncryptLoanCert.pdf.
The alias of the public key that is used to remove encryption is Encryption.
The unsecured PDF document is saved as a PDF file named noEncryptionLoan.pdf.
(See Removing Certificate Based 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 RemovePKIEncryption.ServiceReference1;
namespace RemovePKIEncryption
{
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 PKI encrypted PDF document
BLOB inDoc = new BLOB();
//Specify the location of the PKI encrypted PDF document
string path = "C:\\Adobe\EncryptLoanCert.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;
//Remove PKI encryption from the PDF document
BLOB outDoc = encryptClient.removePDFCertificateSecurity(inDoc, "Encryption");
//Populate a byte array with BLOB data
byte[] outByteArray = outDoc.MTOM;
//Create a new file that represents the unencrypted 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);
}
}
}
}
|
|
|