IMPORTANT:
The functions within this FLL have changed. Please refer to the latest
documention for the VFP Encryption FLL that can be found at the
following link:
Major VFP Encryption Update
Important Fixes
It's 4:00 AM and I have some pressing stuff that I need to get done for a UK client. However, I did dive into the FLL again and I have fixed a couple problems that I was alerted to by Glenn Domeracki (by the way, great job Glenn - I really appreciated the feedback and repro code). All known issues with the FLL have been fixed.
Important Changes
Also, I felt that the Hash function was so simple and elegant, that I would try and do the same with the encryption functions. So now there are only two encryption functions Encrypt() and Decrypt(). I will make future changes backward compatible, but this change had to be made (it makes it far more maintainable and understandable). The FLL has only been available on this blog for a couple of days, so I felt if I was going to change the function signatures, now was the time.
I've also added another encryption algorithm... Tiny Encryption Algorithm (TEA). It's a secure, blazingly fast, encryption algorithm. So now the FLL gives access to: AES128, AES192, AES256, Blowfish, and TEA. And each of them is provided in ECB, CBC, and CFB modes. So, that is basically 15 different ways to encrypt strings.
Still to Come
I'm still working on the EncryptFile() and DecryptFile() functions... should be fully functional and debugged soon. But as I've mentioned in earlier blog entries, using the STRTOFILE() and FILETOSTR() Visual Foxpro functions in conjunction with the FLL functions will give you a way to encrypt files until I finish the file manipulation portion.
OK, I don't have a lot of time to document the new functions or go into them in detail (I'll be back later), for now here is the download link for the VFP Encryption FLL and some sample code (I hope the sample code gives you the general idea until I can come back and detail this further).
Special Thanks to George Anescu
But before I go... I can't say enough good stuff about the encryption and hashing classes that George Anescu created. This entire project would have been 10 times as hard without the awesome amount of work he put into his C++ projects. Thanks George, and know that it is very much appreciated that you have placed this information into the public domain - it has allowed me to create a great derivative work for Visual FoxPro. Make sure to read George's disclaimer that I have been including in the readme.txt that comes with the download.
Download the VFP Encryption FLL (58 KB approx.)
*!* Sample Code *!*
SET LIBRARY TO LOCFILE("vfpencryption.fll") && contains encryption and has functions for use in Visual FoxPro
*!* Example Keys - make your own unique keys
#DEFINE A128BITKEY "!`/_b}B#JXRp}Bsn"
#DEFINE A192BITKEY "fGSoTa3M?{#NOsOBGqmEd>e'"
#DEFINE A256BITKEY "LVE*(zz}}'rr)`P%wDq@lc8WWbGw0[77"
#DEFINE A448BITKEY ":E9}$6+a7ifN)#G')/&[ZpM$4Z.JOy@M&{^%JFOd2Ew{A?=dxB]RB9un"
*!* There are three modes for these ciphers
DIMENSION aryModes(3)
aryModes(1) = "ECB MODE" && Electronic Code Book
aryModes(2) = "CBC MODE" && Cipher Block Chaining
aryModes(3) = "CFB MODE" && Cipher Feedback
*!* AES (a.k.a. Rijndael) is the king of encryption currently - extremely secure
*!* Blowfish is popular, good mix of security and speed
*!* Tiny Encryption Algorithm (TEA) is secure and extremely fast
LOCAL lcStringToEncrypt, lcEncrypted
lcStringToEncrypt = "Visual FoxPro Rocks!"
CLEAR
FOR lnCounter = 0 TO 2 && lets loop through all the available ways to encrypt a string (15 in all)
?"AES128:(" + aryModes(lnCounter + 1) + ")"
lcEncrypted = Encrypt(lcStringToEncrypt, A128BITKEY, 0, lnCounter)
?lcEncrypted
?Decrypt(lcEncrypted, A128BITKEY, 0, lnCounter)
?
?"AES192:(" + aryModes(lnCounter + 1) + ")"
lcEncrypted = Encrypt(lcStringToEncrypt, A192BITKEY, 1, lnCounter)
?lcEncrypted
?Decrypt(lcEncrypted, A192BITKEY, 1, lnCounter)
?
?"AES256:(" + aryModes(lnCounter + 1) + ")"
lcEncrypted = Encrypt(lcStringToEncrypt, A256BITKEY, 2, lnCounter)
?lcEncrypted
?Decrypt(lcEncrypted, A256BITKEY, 2, lnCounter)
?
?"Blowfish448 - 16 round:(" + aryModes(lnCounter + 1) + ")"
lcEncrypted = Encrypt(lcStringToEncrypt, A448BITKEY, 4, lnCounter)
?lcEncrypted
?Decrypt(lcEncrypted, A448BITKEY, 4, lnCounter)
?
?"TEA128:(" + aryModes(lnCounter + 1) + ")"
lcEncrypted = Encrypt(lcStringToEncrypt, A128BITKEY, 8, lnCounter)
?lcEncrypted
?Decrypt(lcEncrypted, A128BITKEY, 8, lnCounter)
?
ENDFOR