# Sunday, August 28, 2005


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:

http://www.sweetpotatosoftware.com/SPSBlog/PermaLink,guid,db662a8f-d47c-46c8-b0d2-a591c20d024b.aspx



Advanced Encryption Standard (AES) For Visual FoxPro
If you read my last blog entry, then you know I'm working on putting together a comprehensive set of encryption/decryption functions for Visual FoxPro via an FLL. Building on that, I decided the next cipher I would implement was AES (a.k.a. Rijndael). The Visual C++ code is based on earlier work by Szymon Stefanek, Vincent Rijmen, and K.U.Leuven that is in the public domain. The AES encryption standard is good enough that it is approved by the US government (among others) for encrypting Classified and Top Secret information. This is arguably one of the best ciphers currently being used, and I wouldn't be surprised if some of you readying this have had AES be a security requirement on some of your projects. For additional information regarding AES you can see the following link:

http://en.wikipedia.org/wiki/AES

Description of the new Visual FoxPro AES Encryption Functions

Function Signatures
AesEncrypt(cString, cKey, [nMode, [nKeySize]])
AesDecrypt(cString, cKey, [nMode, [nKeySize]])

Parameters
cString: String to encrypt/decrypt
cKey: Encryption Key to use (16, 24, or 32 characters depending on nKeySize)*
nMode: AES Mode (1 = ECB 2 = CBC)
nKeySize: Size of Key in bits (128, 192, 256)

* The cKey parameter will accept keys that aren't the right size and either pad or truncate them in order to provide the internal FLL function with the correct key length, however this weakens the overall security of the AES encryption and is strongly discouraged.

Download the FLL and Start Using AES in Visual FoxPro
Here is the download link and some cut-paste-and-execute sample code so you can try it out. NOTE: I will be overwriting prior versions of the fll so the links always point to the latest version. Also, should you want to see a specific cipher or hash implemented in this FLL, or if you have some other suggestions/ideas, please feel free to leave me a comment about it and I will see what I can do.

Download the VFP Encryption FLL (22 KB approx.)

Example of Use

CLEAR
SET LIBRARY TO LOCFILE("vfpencryption.fll")
#DEFINE ASECRET256BITKEY "LVE*(zz}}'rr)`P%wDq@lc8WWbGw0[77" && Example only, make your own 32 character key
? "__________________________"
? "EXAMPLE #1 (simplest): USES DEFAULT AES - CBC MODE 256-BIT KEY"
cEncryptedString = AesEncrypt("Visual FoxPro Rocks!", ASECRET256BITKEY)
cDecryptedString = AesDecrypt(cEncryptedString, ASECRET256BITKEY)
? "Encrypted: " + cEncryptedString
? "Decrypted: " + cDecryptedString
? "__________________________"
? "EXAMPLE #2: USES AES - ECB MODE 256-BIT KEY"
cEncryptedString = AesEncrypt("Visual FoxPro Rocks!", ASECRET256BITKEY, 1, 256)
cDecryptedString = AesDecrypt(cEncryptedString, ASECRET256BITKEY, 1, 256)
? "Encrypted: " + cEncryptedString
? "Decrypted: " + cDecryptedString
? "__________________________"
? "EXAMPLE #3: USES AES - CBC MODE 256-BIT KEY"
cEncryptedString = AesEncrypt("Visual FoxPro Rocks!", ASECRET256BITKEY, 2, 256)
cDecryptedString = AesDecrypt(cEncryptedString, ASECRET256BITKEY, 2, 256)
? "Encrypted: " + cEncryptedString
? "Decrypted: " + cDecryptedString
? "__________________________"
#DEFINE ASECRET192BITKEY "!rPrrj<t!fr7$7L?1#\\;lAV" && Example only, make your own 24 character key
? "EXAMPLE #4: USES AES - ECB MODE 192-BIT KEY"
cEncryptedString = AesEncrypt("Visual FoxPro Rocks!", ASECRET192BITKEY, 1, 192)
cDecryptedString = AesDecrypt(cEncryptedString, ASECRET192BITKEY, 1, 192)
? "Encrypted: " + cEncryptedString
? "Decrypted: " + cDecryptedString
? "__________________________"
? "EXAMPLE #5: USES AES - CBC MODE 192-BIT KEY"
cEncryptedString = AesEncrypt("Visual FoxPro Rocks!", ASECRET192BITKEY, 2, 192)
cDecryptedString = AesDecrypt(cEncryptedString, ASECRET192BITKEY, 2, 192)
? "Encrypted: " + cEncryptedString
? "Decrypted: " + cDecryptedString
? "__________________________"
#DEFINE ASECRET128BITKEY "!rPrrj<t!fr7$7L?1#\\;lAV" && Example only, make your own 16 character key
? "EXAMPLE #6: USES AES - ECB MODE 128-BIT KEY"
cEncryptedString = AesEncrypt("Visual FoxPro Rocks!", ASECRET128BITKEY, 1, 128)
cDecryptedString = AesDecrypt(cEncryptedString, ASECRET128BITKEY, 1, 128)
? "Encrypted: " + cEncryptedString
? "Decrypted: " + cDecryptedString
? "__________________________"
? "EXAMPLE #7: USES AES - CBC MODE 128-BIT KEY"
cEncryptedString = AesEncrypt("Visual FoxPro Rocks!", ASECRET128BITKEY, 2, 128)
cDecryptedString = AesDecrypt(cEncryptedString, ASECRET128BITKEY, 2, 128)
? "Encrypted: " + cEncryptedString
? "Decrypted: " + cDecryptedString

Sunday, August 28, 2005 10:46:53 PM (GMT Daylight Time, UTC+01:00)  #    Comments [3]

 

Archive

<July 2009>
SunMonTueWedThuFriSat
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678