Skip to main content
Aloaha Software

Aloaha PDF Crypter

Go Search
Home
Aloaha PDF Suite
Aloaha PDF Signator
Aloaha Smartcard Connector
Aloaha PDF Saver
Aloaha Secure PDF Viewer
Aloaha PDF Crypter
  
Aloaha for professionals > Aloaha PDF Crypter > Shared Documents > LDAPEncryptionSample  

Web Part Page Title Bar image
LDAPEncryptionSample

The easy way to certificate encrypt your PDF Documents

 LDAP PDF Encryption Sample

'The code sample below was created by
'Pedro Leal of aviita solutions
'www.aviita.li
 
using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Reflection;
namespace encrypt
{
    public class PDFEncrypter
    {
        public byte[] encryptPDF(byte[] sourcePDF, string encryptuser)
        {
            string ldap = ConfigurationManager.AppSettings["ldapconnectin"];
            string eku = ConfigurationManager.AppSettings["enhancedkeyusage"];
            byte[] outputPDF = null;
            int ku = 0;
            bool noOverwrite = false;
            //argument array
            object[] objarray = new object[7];
            objarray[0] = ldap;
            objarray[1] = sourcePDF;
            objarray[2] = outputPDF;
            objarray[3] = encryptuser;
            objarray[4] = ku;
            objarray[5] = eku;
            objarray[6] = noOverwrite;
            //modifiers- very importend
            ParameterModifier p = new ParameterModifier(7);
            p[0] = false;
            p[1] = false;
            p[2] = true; //without this, null will return!
            p[3] = false;
            p[4] = false;
            p[5] = false;
            p[6] = false;
            ParameterModifier[] mods = { p };
 
            Type aloahapdf = Type.GetTypeFromProgID("aloahapdf.edit");
            object aloahapdfLateBound = Activator.CreateInstance(aloahapdf);
            string msg = (string)aloahapdf.InvokeMember("encrypt_pdf_by_LDAP_BA"
                , System.Reflection.BindingFlags.Default | System.Reflection.BindingFlags.InvokeMethod
                , null
                , aloahapdfLateBound
                , objarray
                , mods
                , null
                , null);
            outputPDF = (byte[])objarray[2];
            return outputPDF;
        }
    }
}