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

Hashing in Visual FoxPro
There are a few popular hash functions that I thought made good candidates for the VFP Encryption FLL. So, by modifying and adding to some earlier Visual C++ work by George Anescu I implemented the following hashing functions: SHA1, SHA256, SHA384, SHA512, MD5, RIPEMD128, and RIPEMD160. They are now all accessible from in Visual FoxPro using a very simple Hash() function.

Bigger but still relatively small
The hash functions added some size to the FLL that now weighs in at about (108 KB), but I think with everything this FLL offers in the way of encryption and hashing that it is still a pretty respectable size.

Additional information on the implemented hash functions
For additional information on the hash functions now accessible to Visual FoxPro refer to the following links:

I’ve included a ReadMe.txt with the download that shows all of the different functions now available in the vfpencryption.fll. I thought this might be a good thing to have with the FLL should someone stumble acrossed it in the future and not know about this blog. Also, it gives me a place to stick George Anescue’s disclaimer (he’s certainly entitled as the work he’s done is great and I appreciate him allowing other developers such as myself to use and modify it freely). Here is some information from the ReadMe.txt about the Hash() function:

Function Signature
Hash(cStringtoHash[, nHashType])

cString: String to return hash for
nHashType: (possible values and corresponding hash)
1 = SHA1 (a.k.a SHA160)  – 160 bit Digest
2 = SHA256    – 256 bit Digest
3 = SHA384    – 384 bit Digest
4 = SHA512 (default hash type)  – 512 bit Digest
5 = MD5    – 128 bit Digest
6 = RIPEMD128    – 128 bit Digest
7 = RIPEMD256    – 256 bit Digest

Though not always true, it can be generally said of these hash algorithms that the longer the Digest is the more secure the hash is. It would be extremely difficult to find a collision for a string hashed with SHA512, which is the default for this Visual FoxPro Hash() function. A collision, simply put, is when you find another string that would produce the same hash.

In order to represent hashes in the most common form of hexBinary use Visual FoxPro’s STRCONV() function. For example:
?STRCONV(Hash(“Some String”), 15)

Download and Code Sample
As I am adding to this FLL, my examples are designed to just give you enough so you know how to use the new functions being implemented. I will be back at a later time with blog entries that detail the use of this FLL in real world situations for Visual FoxPro. Here is the download link for the FLL and an example of its use:

Download the VFP Encryption FLL (50 KB approx.)

*!* Example of Use *!*
DIMENSION aryHashTypes(7) && used just for this example, not necessary in production code
aryHashTypes(1) = “SHA1”
aryHashTypes(2) = “SHA256”
aryHashTypes(3) = “SHA384”
aryHashTypes(4) = “SHA512 (default hash type)”
aryHashTypes(5) = “MD5”
aryHashTypes(6) = “RIPEMD128”
aryHashTypes(7) = “RIPEMD256”

SET LIBRARY TO LOCFILE(“vfpencryption.fll”)

LOCAL lnCounter, lcHashDigest
FOR lnCounter = 1 TO 7 && iterate through all available hashes
 lcHashDigest = Hash(“Visual FoxPro Rocks!”, lnCounter) && here is the actual function in use
 ?”Binary Characters:”
 ?”hexBinary Equivalent:”
 ?STRCONV(lcHashDigest, 15) && Easy way to get the hexBinary equivalent