EsDES - ActiveX control

Eurosource, Gruvbyn 415, S-820 50 LOOS, Sweden
(info@eurosource.se) (http://www.eurosource.se)
Updated: 1999-05-05 21:45

This control is a cryptographic control that implements a 64-bit DES-encryption/decryption algorithm. It allows DES encryption of strings, buffers and files in an easy and user friendly way.

New features in version 1.1

  1. EsDes can now be used in ASP-applications ( Server side scripting ).

Installation

Transfer EsDes32.OCX to your \windows\system or \winnt35\system32 directory and register it by executing the command:

RegSvr32 \Windows\System\EsDES32.OCX

RegSvr32.exe can be found on the Visual Basic 4.0 CD-ROM and in our dll archive (www.eurosource.se). If RegSvr32.exe fails, it's probably because you don't have the MFC 4.0 DLL library installed on your system. This is available from many sources on the Internet including our ftp archive as MFC40DLL.ZIP. Regsvr32.exe is also included in this archive. If you want to check if you already got the files in mfc40dll.zip they are

  • mfc40.dll
  • msvcrt40.dll
  • oc30.dll
  • olepro32.dll
  • regsvr32.exe

Cookbook or how to use the EsDES Control

 

Create a EsDes object for an ASP application

Use the object ID ESDES.EsDesCtrl.1 when you create an instance of the EsDesCtrl.

So the code

<object RUNAT="server" PROGID="ESDES.EsDesCtrl.1" id="EsDes"> </object>

or

set EsDes = server.CreateObject("EsDes.EsDesCtrl.1")

will create the object for you.

 

Set an encrypt/decrypt key

You can set the key in several ways. As a string, a decimal string and a hexadecimal string. If you read the key back you get it back in the same format as you set it.

Using Hexadecimal values
Set it using a string of hexadecimal values

EsDES1.DesKey = "FF20345645872345"

Using a string of comma separated Decimal values
Set it using a string of decimal values.

EsDES1.DesKey = "12,234,23,1,98,56,99,255"

Using a string of characters
Set it using a string. In this case you should prefix the string with a dollar "$" character

EsDES1.DesKey = "$This is a key string"

Encrypt a string

Most of the methods for EsDES are supplied in pairs as one encryption and one decryption variant. The exception is the EncryptString method which is only supplied as encryption. This is because the result of encryption's can contain zeros in the result and in C/C++, for instance, this is the character that indicate the end of the string. Therefore this method put its result in the buffer and if you want to decrypt its output you have to use the DecryptBuffer method.

Sub EncryptString()
    Dim outp As String
    Dim i As Integer

    ' Set the Key

    EsDES1.DesKey = Text1

    ' Encrypt a string in a textbox txtinstr
    EsDES1.EncryptString txtinstr

    ' The result of the encryption is now in the
    ' buffer and EsDS1.Length is set to the length

    ' of the resulting encrypted data
    ' Decrypt the contents in the buffer

    If ( EsDES1.DecryptBuf = True ) Then
        Lbloutstr = "After decryption = "
        For i = 0 To EsDES1.Length - 1
            Lbloutstr = Lbloutstr + Chr(EsDES1.Buf(i))
        Next i

        MsgBox "OK! Bufferlength = " + str$(EsDES1.Length)

    Else
        MsgBox "Failure in DecryptBuf method."
    End If

End Sub

Encrypt a file

To encrypt an entire file is easy with the EsDES control. In this case we use the common dialogs control to get the file to encrypt and the output file from the user.

Sub EncryptFile()

    Dim fl As Long

    ' Get path for file to encrypt

    CommonDialog1.DialogTitle = "Select file to encrypt"
    CommonDialog1.ShowOpen
    EsDES1.InFile = CommonDialog1.filename
   
    ' Get name for outputfile

    CommonDialog1.DialogTitle = "Choose name for encrypted file"
    CommonDialog1.ShowOpen
    EsDES1.OutFile = CommonDialog1.filename
   
    ' This can be a lengthy operation

    Screen.MousePointer = 11
   
    ' Set the Key

    EsDES1.DesKey = Text1
    DoEvents
    fl = EsDES1.EncryptFile ' Change to EsDes1.DecryptFile to decrypt

    ' Done

    Screen.MousePointer = 0
   
    ' The file length have possibly been enlarged
    ' to be an even multiple of eight

    MsgBox "New FileLength= " + str$(fl)

End Sub

The status event is generated periodically during the encryption of the file and we can use the ProgressBar control and use simple code as the following to indicate to the user how the encryption proceeds.

Private Sub EsDES1_Status( ByVal Progress As Integer )
    ProgressBar1 = Progress
End Sub

Decrypt a file

You use code just the same as that above to Encrypt a file. You only change the line

fl = EsDES1.EncryptFile

to

fl = EsDES1.DecryptFile

Validating the control

When you install the control there is also a sample file and a file named cert.txt that you can use to verify the algorithms. How to do this is exemplified in the sample1 file that comes with the control. Check under the Verify DES Algorithm button.


Properties
Methods
Events


Properties


unsigned char buf(index)

With this property you can fetch or set a value in a certain buffer position. You must first set the buffer length with the length property before you can use the buffer.


LPSTR DesKey

This is the DES-key. You can set this key in several ways.

Using Hexadecimal values

Set it using a string of hexadecimal values

e.g. FF20345645872345

Using a string of comma separated Decimal values

Set it using a string of decimal values e.g. 12,234,23,1,98,56,99,255

Using a string of characters

Set it using a string in this case you should prefix the string with a dollar "$" character

e.g. $This is a key string.

You will get the key back in the same format as you set it. Before you do any encryption/decryption you have to set this property to a value as it have an unknown value before you do.


LPSTR InFile

This is the full path for a file you want to decrypt/encrypt.


long Length

This is the length of the buffer. You must set this property before you can use the buffer. You must always set the buffer to value that is an even multiple of 8. If you don't EsDES will set it to the next highest multiple.


LPSTR OutFile

This is the full path to the output file from a decryption/encryption operation.


Methods


BSTR Decrypt8(LPCTSTR input)

This method decrypts eight characters. The format of the input string can be supplied in several ways and the result is returned in the same format as you give as input. The formats of the input string can be one of the following

Using Hexadecimal values

Set it using a string of hexadecimal values

e.g. FF20345645872345

Using a string of comma separated Decimal values

Set it using a string of decimal values e.g. 12,234,23,1,98,56,99,255

Using a string of characters

Set it using a string in this case you should prefix the string with a dollar "$" character

e.g. $This is a key string. Note that in this case an empty string is returned and the result is returned in the buffer which will have a length of 8.


BOOL DecryptBuf()

This method encrypts the content of the buffer. You must therefore first set the buffer size with the Length property and then fill it with the data that you want to decrypt.


long DecryptFile()

With this method you can Decrypt a file. You specify the full path to the file you want to decrypt in the InFile property and the file you want to have as output in the property OutFile. Status events are generated as the decryption proceeds.


BSTR Encrypt8(LPCTSTR input)

This method encrypts eight characters. The format of the input string can be supplied in several ways and the result is returned in the same format as you give as input. The formats of the input string can be one of the following

Using Hexadecimal values

Set it using a string of hexadecimal values

e.g. FF20345645872345

Using a string of comma separated Decimal values

Set it using a string of decimal values e.g. 12,234,23,1,98,56,99,255

Using a string of characters

Set it using a string in this case you should prefix the string with a dollar "$" character

e.g. $This is a key string. Note that in this case an empty string is returned and the result is returned in the buffer which will have a length of 8.


BOOL EncryptBuf()

This method encrypts the content of the buffer. You must therefore first set the buffer size with the Length property and then fill it with the data that you want to encrypt.


long EncryptFile()

With this method you can Encrypt a file. You specify the full path to the file you want to encrypt in the InFile property and the file you want to have as output in the property OutFile. Status events are generated as the encryption proceeds


void EncryptString(LPCTSTR input)

With this method you can Encrypt a string. As EsDES always work with even multiple of 8 the result, which is placed in the buffer, will have a length that is an even multiple of 8. If you need to store this result away and only want to use the same size for this storage as the original string this is however not a problem. Status events are generated as the encryption proceeds


Events


status (short progress)

Certain operations take some time to complete. This event gives you information about how much of the job that has been completed. When a lengthy job starts the status event is fired with progress set to 0 and then you get status events until the job is complete and a status event with progress set to 100 is fired. You therefore only need to write the progress to a gauge control to give your users dynamic information.


Where to get the control?

It is possible that you are reading this documentation without having access to the control itself. If you have Internet access you just need to connect to http://www.eurosource.se and fetch a fully working sample of the control. At this location you can also find samples on how to use the control.

We can email the control anywhere in the world if you send us a request to do so. Please state if you want MIME or BINHEX coding. Send request to sales@eurosource.se

If you use the unregistered version of the control a splash screen is displayed from time to time reminding you to register.To get rid of this nag-screen you need to register. Information is available at our site.

We ship anywhere in the world with World-wide First Class/Airmail if you select this option. The only media supported is 3.5" diskettes.The charge for this type of delivery is $15 (USD) extra.

Support

You can get support by sending email to support@eurosource.se. You can also find relevant information on-line at http://www.eurosource.se

We also check the newsgroup comp.lang.basic.visual.3rdparty on a regular basis and will try to help on all questions posted there.


How to contact us

  • If you need to contact us the preferred way is through email. Please send a mail to info@eurosource.se
  • If you want to use phone please call us at +46 657 10620 and Fax: +46 657 10612.
  • If you want to send a snailmail you can send it to
  • Eurosource, Gruvbyn 415A, S-820 50 LOOS, SWEDEN