Demo of Blowfish in Visual Basic (VB6/VBA)
This demonstration VB project shows how to use the functions in David Ireland's adaptation of Bruce Schneier's Blowfish algorithm in Visual Basic (VB6/VBA) and other utilities, including base64 encoding. See Blowfish Version 6 Changes for more details on the latest version. To download the source code, go to Blowfish: a Visual Basic version.
For a more complicated example showing CBC mode and raw encryption, see the Blowfish Extended VB Demo Page.
It's a quick-and-dirty demo. There is no error handling, no data checking, and no clearing of sensitive data or other security checks that you'd have in a real project. It's just meant to give developers an idea of how to use the functions.

The three buttons show how to use the VB functions to set the key, encrypt plaintext, and decrypt the ciphertext.
- Set Key: converts the key string entered by the user into a Byte array
and initialises the Blowfish key arrays.
If Me.optHexKey Then ' In hex format aKey() = cv_BytesFromHex(Me.txtKey) Else ' User has provided a plain alpha string aKey() = StrConv(Me.txtKey, vbFromUnicode) End If Call blf_KeyInit(aKey)
- Encrypt it: encrypts the plaintext into ciphertext,
Dim abPlain() As Byte Dim abCipher() As Byte abPlain = StrConv(Me.txtPlain, vbFromUnicode) abCipher = blf_BytesEnc(abPlain)
and displays the ciphertext in different formats:Me.txtCipher = StrConv(abCipher, vbUnicode) Me.txtCipherHex = cv_HexFromBytes(abCipher) Me.txtCipher64 = EncodeBytes64(abCipher)
- as a string of binary characters, mostly 'unprintable' characters, i.e. pretty useless
- in hexadecimal format
- in base64/radix64 format
- Decrypt it: decrypts the ciphertext back into plaintext.
This should be the same as what we started with.
abPlain = blf_BytesDec(abCipher) Me.txtDecrypt = StrConv(abPlain, vbUnicode)
As a refinement, there's an option that shows how the user can specify a key in either hexadecimal form or as just a plain ASCII string. Don't forget to add error checking for invalid characters in your code.

The active key is displayed in hexadecimal format. In this case, we have the a key consisting of eight bytes "p"=0x70, "a"=0x61, "s"=0x73, etc.
See also
Back to the Cryptography Page.
Contact us
To comment on this page or to contact us, please send us a message.
This page last updated 9 September 2025.