Chelsfield Cypher Library

How to use CSpmrbc.dll

Contents   Overview   Registration   Support   Operation   Purchase   FAQ

There are a few essential steps one needs to take before attempting to using the Chelsfield Cypher Library

1)  Use the CypherSetup.exe Utility to extract CSpmrbc_UNLICENSED.dll or unlock and extract CSpmrbc.dll

2)  Register the CSpmrbc.dll or CSpmrbc_UNLICENSED.dll library file. To do this, open a DOS box and at the Windows command prompt type the following:
regsvr32.exe [path]CSpmrbc.dll

3)  Create a code reference to the registered file. To do this, from the VB IDE Project Menu select "References...", and from the list, ensure that the item "Chelsfield Cypher Library" is checked (ticked).

Data Stream ENCRYPTION Syntax is:  strResult = object.CS_EncryptBC(strFileData, strPassword, lngVerbose)

Parameter Data Type Description
strResult String Receives the encrypted string
strFileData String String to encode
strPassword  String Password string, any set of characters
lngVerbose  Long Assign a value of -2 [ Required ] 


Data Stream DECRYPTION Syntax is: strResult = object.CS_DecryptBC(strEncrypted, strPassword, lngVerbose)

Parameter Data Type Description
strResult String Receives the decoded string
strEncrypted String Encoded string to decode
strPassword  String Password string, any set of characters.
lngVerbose Long 1 If the password is wrong then the function returns the following text: "Error #525: Bad Password"
    -1 shows a message box if the password is incorrect
0 suppresses all messages. If the password is wrong  there will be no attempt at decryption.

 
The following shows a simple code example of how the library is applied. You could cut and paste this, but if you do, make sure that CRLF line endings are preserved and that line endings are not wrapped or truncated etc.  In any event, a complete working project version of this code, can be found in the [ VBExample ] folder.

  

Dim strEncrypted As String

'cmdEncrypt_aStrFile = Routine that shows encryption of a string
'cmdDecrypt_aStrFile = Shows decryption (recovery) of the same string

Private Sub cmdEncrypt_aStrFile()
'**************************************************************************
'* This routine shows the basic method of encryption. This example        *
'* takes plain text from an existing text box, but any text (or binary    *
'* data) contained in a string variable could be used.                    *
'*                                                                        *
'* Notice that the encrypted result is passed to a string variable not    *
'* to a text box. Although the textbox, tbEncryptedText, used here, shows *
'* the encrypted result, this is for illustrative purposes only. Text     *
'* boxes can only show "printable" characters, and can't be used to       *
'* store binary data.                                                     *
'*************************************************************************

Dim OrgString As String, strPassword As String
Dim MC As CSCypherLib
Set MC = New CSCypherLib                 'Instantiate the class

OrgString = tbTexttoEncrypt.Text         'Get some text from text box
strPassword = RTrim$(tbEncryptPw.Text)   'Make sure we know the true length of the password!

strEncrypted = MC.CS_EncryptBC(OrgString, strPassword, -2) 'Encrypt and store in strEncrypted
tbEncryptedText.Text = strEncrypted      'Show result in text box
Set MC = Nothing                         'Destroy cypher object
End Sub

Private Sub cmdDecrypt_aStrFile()
'**************************************************************************
'* This routine shows the method of decryption, it takes encrypted data   *
'* from the string variable (strEncrypted) which is used to contain the   *
'* cyphertext or encrypted binary data.                                   *
'**************************************************************************

Dim encString As String, strPassword As String
Dim MC As CSCypherLib
Set MC = New CSCypherLib                 'Instantiate the class

encString = strEncrypted                 'Read encrypted string from variable (not from text box)
If Len(encString) < 56 Then Exit Sub     'On this example do a crude check to see if we actually have _
something to decode

strPassword = RTrim$(tbDecryptPw.Text)   'Make sure we know the true length of the password!
tbDecryptedText.Text = MC.CS_DecryptBC(encString, strPassword, -1) 'As the original string was taken from a _
text box, we can decode direct to another Text box

Set MC = Nothing                         'Clean up
End Sub

 

'Encrypt_File = Routine that demonstrates encryption of a file
'Decrypt_File = Shows decryption (recovery) of the same file

Private Sub Encrypt_File()
'*************************************************************************
'* This routine shows the basic method of file encryption. It takes an   *
'* existing .jpg graphics file ( Pooch.jpg ) found in the VBExamples     *
'* folder, encrypts it, and saves the result with a .cs$ extension.      *
'* For the purposes of demonstration the file name/path and password     *
'* are hard coded.                                                       *
'*************************************************************************

Dim strCurrentFile As String, strFileData As String, strPassword As String

Dim MC As CSCypherLib
Set MC = New CSCypherLib                      'Instantiate the class

strCurrentFile = App.Path & "\Pooch.jpg"      'Select some arbitrary File
strPassword = "apass$tr1ng"                   'Set a password

On Error GoTo FileOrPathError                 'Turn on error trap for file/path access
strFileData = String(FileLen(strCurrentFile), " ") 'Read the whole file
On Error GoTo 0                               'Turn off trap

lngFilebuff = Freefile
Open strCurrentFile For Binary As lngFilebuff
    Get lngFilebuff, , strFileData            'Get the file data
Close lngFilebuff

strEncrypted = MC.CS_EncryptBC(strFileData, strPassword, -2) 'Encrypt the File Data
strCurrentFile = Mid$(strCurrentFile, 1, Len(strCurrentFile) - 3) & "cs$" 'Change File Extension so that _
we don't overwrite the original in this example

lngFilebuff = Freefile
Open strCurrentFile For Binary As lngFilebuff 'Write out the encoded file
    Put lngFilebuff, , strEncrypted
Close
MsgBox " ENCRYPTED File Saved with the new File Extension [ cs$ ] ", vbOKOnly + vbInformation, "Encrypted File: SUCCESS"
Set MC = Nothing                              'Destroy cypher object

Exit Sub
FileOrPathError:
MsgBox " Can't find the File or Path of the specified file ", vbOKOnly + vbExclamation, "Encrypted File: FAIL"
Set MC = Nothing
End Sub

Private Sub Decrypt_File() 
'**************************************************************************
'* This routine shows the basic method of file decryption. It takes the   *
'* file Pooch.cs$ created as a result of running Encrypt_File, decrypts   *
'* it and restores the original file name ( Pooch.jpg ) by replacing the  *
'* the .cs$ extension with .jpg. You might delete Pooch.jpg to check      *
'* file restoration.                                                      *
'**************************************************************************

Dim strCurrentFile As String, strFileData As String, strPassword As String
Dim MC As CSCypherLib
Set MC = New CSCypherLib                      'Instantiate the class

strCurrentFile = App.Path & "\Pooch.cs$"      'Get the encrypted file
strPassword = "apass$tr1ng"                   'Use the original password

On Error GoTo FileOrPathError                 'Turn on error trap for file/path access
strEncrypted = String(FileLen(strCurrentFile), " ") 'Read the whole file
On Error GoTo 0                               'Turn off trap

lngFilebuff = Freefile
Open strCurrentFile For Binary As lngFilebuff
    Get lngFilebuff, , strEncrypted           'Get the encrypted data
Close lngFilebuff

strFileData = MC.CS_DecryptBC(strEncrypted, strPassword, -1) 'Decrypt the File Data
strCurrentFile = Mid$(strCurrentFile, 1, Len(strCurrentFile) - 3) & "jpg" 'Restore the File Extension, This _
will overwrite the original file

lngFilebuff = Freefile
Open strCurrentFile For Binary As lngFilebuff 'Write out the decoded file
    Put lngFilebuff, , strFileData
Close                                         'Close all open file buffers 
MsgBox " The Original File has been Overwritten/Restored ", vbOKOnly + vbInformation, "Decrypted File: SUCCESS"
Set MC = Nothing                                     
Exit Sub
FileOrPathError:
MsgBox " Can't find the Encrypted [ .cs$ ] File Specified ", vbOKOnly + vbExclamation, "Decrypted File: FAIL"
Set MC = Nothing                              'Make sure we clean up in case of error  
End Sub


Contents   Overview   Registration   Support   Operation   Purchase   FAQ

Lower Farm House  Little Barford  St. Neots  Cambridgeshire  PE19 6YE 
Tel: +44 ( 0)1480 472446   E-mail: sales@chelsfieldsolutions.com