Module: Encryption in Category General VBA/VB6 : Encryption and Compression from Total Visual SourceBook

Encrypt and decrypt a Unicode or ASCII string using XOR password encryption in VBA and VB6.

Similar to class CEncryption but simplified for function calls and no progress events.

Procedure Name Type Description
(Declarations) Declarations Declarations and private variables for the modEncryption module.
EncryptString Procedure Encrypt/Decrypt a string with XOR encryption with support for Unicode. The encrypted string produced by the method is reversible. This means that if you encrypt a string, then encrypt the results of that operation, the original string is restored.
Note: The same password must be supplied to successfully decrypt the string. See the example tab for a demonstration of this. If you need an ASCII version of this function, use the EncryptStringAscii method.
EncryptStringAscii Procedure Encrypt/Decrypt a string with XOR encryption, returning the result in ASCII format. The encrypted string produced by the method is reversible. This means that if you encrypt a string, then encrypt the results of that operation, the original string is restored.
Note: The same password must be supplied to successfully decrypt the string. See the example tab for a demonstration of this. The EncryptStringAscii method returns the result in ASCII format. If you need to pass the results of the EncryptString function on the command line, or use it external to your program, it is recommended that you use the ASCII version of this function.
EncryptByte Procedure Encrypt one byte, and modify the password. Modifying the password as we encrypt makes the encryption slightly harder to break.
' Example of modEncryption
'
' To use this example, create a new module and paste this code into it.
' Then run the procedure by putting the cursor in the procedure and pressing:
'    F5 to run it, or
'    F8 to step through it line-by-line (see the Debug menu for more options)

Private Sub Example_modEncryption()
  ' Comments: Examples of modEncryption to encrypt and unencrypt a string with a password in VBA and VB6.
  '           See the Immediate Window for the results.

  Const cstrExample As String = "One small step for [a] man; one giant leap for mankind"
  Const cstrPassword As String = "password"

  Dim strString As String

  Debug.Print "Original String: " & cstrExample
  Debug.Print

  ' Example of Unicode encrypting and decrypting strings.
  strString = EncryptString(cstrExample, cstrPassword)
  Debug.Print "Encrypted String: " & strString

  strString = EncryptString(strString, cstrPassword)
  Debug.Print "Un-Encrypted String: " & strString
  Debug.Print

  ' Example of ASCII encrypting and decrypting strings.
  strString = EncryptStringAscii(cstrExample, cstrPassword)
  Debug.Print "ASCII Encrypted String: " & strString

  strString = EncryptStringAscii(strString, cstrPassword)
  Debug.Print "ASCII Un-Encrypted String: " & strString

End Sub

Total Visual SourceBook The source code in Total Visual Sourcebook includes modules and classes for Microsoft Access, Visual Basic 6 (VB6), and Visual Basic for Applications (VBA) developers. Easily add this professionally written, tested, and documented royalty-free code into your applications to simplify your application development efforts.

Total Visual SourceBook is written for the needs of a developer using a source code library covering the many challenges you face. Countless developers over the years have told us they learned some or much of their development skills and tricks from our code. You can too!

Additional Resources

Total Visual SourceBook CD and Printed Manual

Microsoft Access/ Office 2016, 2013, 2010, and 2007 Version
is Shipping!

New features in Total Visual SourceBook for Access, Office and VB6

Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!


View all FMS products for Microsoft Access All Our Microsoft Access Products

Reviews

Reader Choice Award for MS Access Source Code Library
Reader Choice

"The code is exactly how I would like to write code and the algorithms used are very efficient and well-documented."

Van T. Dinh, Microsoft MVP

SourceBook Info

Additional Info

Question

 

 

Free Product Catalog from FMS