Monday, August 06, 2007

The free vfpencryption71.fll has been updated. Changes include:

  • Bug fix for a very obscure problem when encrypting and decrypting Jpg image files using AES 256
  • Added a CRC() and CRCFile() function that produces 16 and 32 bit CRCs for Strings and Files
  • Added HashRecord() and CRCRecord() functions that allow a VFP developer to quickly and easily generate Hashes or CRCs for the current record in an opened table

Download the Latest Version of the VFP Encryption 71 FLL (63 KB approx.)


 vfpencryption.fll Documentation...

Function ENCRYPT()

Signature: Encrypt(cStringtoEncrypt, cSecretKey[, nEncryptionType[, nEncryptionMode]])

Parameters:

cStringtoEncrypt - A plain text string that you want to have encrypted, such as "Hello World!"

cSecretKey - A plain text string that is the Key you want used during encryption, such as "My_SeCrEt_KeY".
Please note that keys may need to be of a particular length for certain types of encryption. Refer below for more information.

nEncryptionType - There are currently 5 types of encryption available. The value of this parameter determines that type of encryption used and how long your Secret Key should be. A single character in Visual FoxPro is  equal to 1 byte or 8 bits. So an encryption algorithm requiring a 128-bit key would need a Secret Key of 16 characters (16 x 8 = 128).

   0 = AES128 (requires a 16 character Key)
   1 = AES192 (requires a 24 character Key)
   2 = AES256 (requires a 32 character Key) *Default
   4 = Blowfish (requires a 56 character Key)
   8 = TEA (requires a 16 character Key)
   1024 = RC4 (Key can be any length)

nEncryptionMode - There are three different modes available for the each of the encryption types listed above. They include: Electronic Code Book (ECB), Cipher Block Chaining (CBC) and Cipher Feedback Block (CFB). The nEncryptionMode parameter does not apply to RC4 encryption (nEncryptionType = 1024).

   0 = ECB *Default
   1 = CBC
   2 = CFB

Return Value:

Character data type - the encrypted form of cStringtoEncrypt.

Remarks:

When saving the return value of Encrypt() function to a field in a table, remember that Visual FoxPro will append blanks to the end of the string in order to fill the character field to its designated length. This can cause problems when decrypting the data as the spaces will be considered part of the encrypted string. To work around this, I suggest placing a single CHR(0) at the end of the encrypted string when saving it to the table. Then when decrypting the data just the portion prior to the CHR(0) can be sent into the Decrypt() function. This does not apply when using RC4 encryption (nEncryptionType = 1024).


Function DECRYPT()

Signature: Decrypt(cEncryptString, cSecretKey[, nDecryptionType[, nDecryptionMode]])

Parameters:

cEncryptedString - A string that has been encrypted using the Encrypt() function.

cSecretKey - A plain text string that is the same Key that you used when you encrypted the data using the Encrypt function, such as "My_SeCrEt_KeY".
Please note that keys may need to be of a particular length for certain types of decryption. Refer below for more information.

nDecryptionType - There are currently 5 types of decryption available and they correspond to the same ones available in Encrypt(). A single character in Visual FoxPro is  equal to 1 byte or 8 bits. So an decryption algorithm requiring a 128-bit key would need a Secret Key of 16 characters (16 x 8 = 128).

   0 = AES128 (requires a 16 character Key)
   1 = AES192 (requires a 24 character Key)
   2 = AES256 (requires a 32 character Key) *Default
   4 = Blowfish (requires a 56 character Key)
   8 = TEA (requires a 16 character Key)
   1024 = RC4 (Key can be any length)

nDecryptionMode - There are three different modes available for the each of the encryption types listed above. They include: Electronic Code Book (ECB), Cipher Block Chaining (CBC) and Cipher Feedback Block (CFB). The nDecryptionMode parameter does not apply to RC4 decryption (nDecryptionType = 1024).

   0 = ECB *Default
   1 = CBC
   2 = CFB

Return Value:

Character data type - the decrypted form of cEncryptedString followed by a variable number of CHR(0)s. See Remarks below for further clarification

Remarks:

IMPORTANT: Decryption is done on blocks of memory, so when the decrypt function returns the encrypted string it will be followed by a variable number of CHR(0)s unless the decrypted string just happens to end at exactly the same location as the last block decrypted. These extraneous CHR(0)'s can be removed using a number of Visual FoxPro functions, such as STRTRAN(), CHRTRAN(), or a combination of LEFT() and AT(). This does not apply when using RC4 decryption (nDecryptionType = 1024).



Function ENCRYPTFILE()

Signature: EncryptFile(cFiletoEncrypt, cDestinationFile, cSecretKey[, nEncryptionType[, nEncryptionMode]])

Parameters:

cFiletoEncrypt - A plain text string that is the fullpath to the file you wish to be encrypted, such as "C:\SensitiveInfo.doc"

cDestinationFile - A plain text string that is the fullpath to an encrypted file you wish to have created on disk, such as "C:\EncryptedInfo.doc". If this file doesn't exist then it will be created for you.

cSecretKey - A plain text string that is the Key you want used during encryption, such as "My_SeCrEt_KeY".
Please note that keys may need to be of a particular length for certain types of encryption. Refer below for more information.

nEncryptionType - There are currently 5 types of encryption available. The value of this parameter determines that type of encryption used and how long your Secret Key should be. A single character in Visual FoxPro is  equal to 1 byte or 8 bits. So an encryption algorithm requiring a 128-bit key would need a Secret Key of 16 characters (16 x 8 = 128).

   0 = AES128 (requires a 16 character Key)
   1 = AES192 (requires a 24 character Key)
   2 = AES256 (requires a 32 character Key) *Default
   4 = Blowfish (requires a 56 character Key)
   8 = TEA (requires a 16 character Key)
   1024 = RC4 (Key can be any length)

nEncryptionMode - There are three different modes available for the each of the encryption types listed above. They include: Electronic Code Book (ECB), Cipher Block Chaining (CBC) and Cipher Feedback Block (CFB). This does not apply when using RC4 encryption (nEncryptionType = 1024).

   0 = ECB *Default
   1 = CBC
   2 = CFB

Return Value:

None

Remarks:

Currently the cFiletoEncrypt and cDestinationFile parameters cannot point to the same file. This may be revised in a future version. But for safety sake, this function requires that the original file be left untouched.



Function DECRYPTFILE()

Signature: DecryptFile(cEncryptedFile, cDestinationFile, cSecretKey[, nDecryptionType[, nDecryptionMode]])

Parameters:

cEncyptedFile - A plain text string that is the fullpath to the file you wish to be decrypted, such as "C:\EncryptedInfo.doc"

cDestinationFile - A plain text string that is the fullpath to a decrypted file you wish to have created on disk, such as "C:\SensitiveInfo.doc". If this file doesn't exist then it will be created for you.

cSecretKey - A plain text string that is the same Key that you used when you encrypted the data using the Encrypt function, such as "My_SeCrEt_KeY".
Please note that keys may need to be of a particular length for certain types of decryption. Refer below for more information.

nDecryptionType - There are currently 5 types of decryption available and they correspond to the same ones available in Encrypt(). A single character in Visual FoxPro is  equal to 1 byte or 8 bits. So an decryption algorithm requiring a 128-bit key would need a Secret Key of 16 characters (16 x 8 = 128).

   0 = AES128 (requires a 16 character Key)
   1 = AES192 (requires a 24 character Key)
   2 = AES256 (requires a 32 character Key) *Default
   4 = Blowfish (requires a 56 character Key)
   8 = TEA (requires a 16 character Key)
   1024 = RC4 (Key can be any length)

nDecryptionMode - There are three different modes available for the each of the encryption types listed above. They include: Electronic Code Book (ECB), Cipher Block Chaining (CBC) and Cipher Feedback Block (CFB). This does not apply when using RC4 decryption (nDecryptionType = 1024).

   0 = ECB *Default
   1 = CBC
   2 = CFB

Return Value:

None

Remarks:

As with EncryptFile(), the cFiletoEncrypt and cDestinationFile parameters cannot point to the same file.


Function HASH()

Signature: Hash(cStringtoHash[, nHashType])

Parameters:

cStringtoHash - A plain text string you wish to have hashed

nHashType - The type of hash function to generate. There are currently 7 different hash functions supported

1 = SHA1 (a.k.a SHA160)
2 = SHA256
3 = SHA384
4 = SHA512 *Default
5 = MD5
6 = RIPEMD128
7 = RIPEMD256

Return Value:

Binary Character Data - the hash for cStringtoHash.

Remarks:

The hash is returned as a series of binary characters. However, it is more common to see hashes in a hexBinary format. This can be accomplished in Visual FoxPro by taking the return of the Hash() function and sending it in as a parameter to the STRCONV() function. For example:

?STRCONV(Hash("Some String"), 15) && hexBinary Hash


Function HASHFILE()

Signature: HashFile(cFileName[, nHashType])

Parameters:

cFileName - The fullpath and name of an existing file you wish to generate a message digest for

nHashType - The type of hash function to generate. There are currently 7 different hash functions supported

1 = SHA1 (a.k.a SHA160)
2 = SHA256
3 = SHA384
4 = SHA512 *Default
5 = MD5
6 = RIPEMD128
7 = RIPEMD256

Return Value:

Binary Character Data - the hash for cFileName.

Remarks:

The hash is returned as a series of binary characters. However, it is more common to see hashes in a hexBinary format. This can be accomplished in Visual FoxPro by taking the return of the HashFile() function and sending it in as a parameter to the STRCONV() function. For example:

?STRCONV(HashFile("C:\MyFile.txt"), 15) && hexBinary Hash


Function HASHRECORD()

Signature: HashRecord(cAlias[, nHashType[,lIncludeMemos]])

Parameters:

cAlias - The table alias containing the record to be hashed

nHashType - The type of hash function to generate. There are currently 7 different hash functions supported

1 = SHA1 (a.k.a SHA160)
2 = SHA256
3 = SHA384
4 = SHA512 *Default
5 = MD5
6 = RIPEMD128
7 = RIPEMD256

lIncludeMemos - Flag determining whether Memo fields should be included when generating the message digest. .T. = Include Memo Fields, .F. = Exclude Memo Fields

Return Value:

Binary Character Data - the hash for the current record in cAlias.

Remarks:

The hash is returned as a series of binary characters. However, it is more common to see hashes in a hexBinary format. This can be accomplished in Visual FoxPro by taking the return of the HashRecord() function and sending it in as a parameter to the STRCONV() function. For example:

?STRCONV(HashRecord("MyTable",5,.T.), 15) && hexBinary Hash


Function CRC()

Signature: CRC(cExpression[, nCRCType])

Parameters:

cExpression - The string you wish to have a CRC generated for

nCRCType - The type of CRC to generate. There are currently 2 different CRC types supported

1 = 16-bit
2 = 32-bit

Return Value:

Numeric Data - the CRC for cExpression.

Remarks:

The CRC that is returned is unsigned, which means that the returned 16-bit CRC needs to be treated as a 4 Byte numeric value and the 32-bit CRC as a 8 byte numeric value in Visual FoxPro. The operation of the CRC() function presented here is quite similar to Visual FoxPro's Sys(2007) function, however you will find that creation of 32-bit CRCs is much faster using this function.


Function CRCFILE()

Signature: CRCFile(cFileName[, nCRCType])

Parameters:

cFileName - The fullpath and name of an existing file you wish to generate a CRC for

nCRCType - The type of CRC to generate. There are currently 2 different CRC types supported

1 = 16-bit
2 = 32-bit

Return Value:

Numeric Data - the CRC for cFileName.

Remarks:

The CRC that is returned is unsigned, which means that the returned 16-bit CRC needs to be treated as a 4 Byte numeric value and the 32-bit CRC as a 8 byte numeric value in Visual FoxPro.


Function CRCRECORD()

Signature: CRChRecord(cAlias[, nCRCType[,lIncludeMemos]])

Parameters:

cAlias - The table alias containing the record to be hashed

nCRCType - The type of CRC to generate. There are currently 2 different CRC types supported

1 = 16-bit
2 = 32-bit

lIncludeMemos - Flag determining whether Memo fields should be included when generating the message digest. .T. = Include Memo Fields, .F. = Exclude Memo Fields

Return Value:

Numeric Data - the CRC for the current record in cAlias .

Remarks:

The CRC that is returned is unsigned, which means that the returned 16-bit CRC needs to be treated as a 4 Byte numeric value and the 32-bit CRC as a 8 byte numeric value in Visual FoxPro. The operation of the CRC() function presented here is quite similar to Visual FoxPro's Sys(2017) function, however you will find that this CRC function is faster than Visual FoxPro's Sys(2017). Also, this function allows you to specify a table alias, which allows CRCs to be created for a record in a table other than the currently selected work area. On the downside, this function does not allow you to specify a comma delimited list of fields to exclude like Sys(2017) does.




Monday, August 06, 2007 7:24:00 AM (Central Daylight Time, UTC-05:00)  #    Comments [12]
Tuesday, August 07, 2007 2:57:36 PM (Central Daylight Time, UTC-05:00)
Congratulation for vfpencryption.fll. I want to view any change about table, and HashFile() is OK !!! If you need help sometimes, you can mail me.
Dragos (foxite Apple)
Friday, August 10, 2007 9:33:41 AM (Central Daylight Time, UTC-05:00)
Thanks for the kind words Dragos. It's amazing what one can do with hashes... from hiding passwords securely to checking for changes in a table or record to even the stuff I used an MD5 hash for in that assembly that allows VFP devs to write .NET code in VFP. I also appreciate the offer to help, I might just take you up on that.
Friday, August 17, 2007 5:44:54 PM (Central Daylight Time, UTC-05:00)
Hi Craig,

Thanks for you contribution with vfpencryption.fll. Now, I am using Cryptor Control for encryp DBF tables, I want to know If the vfpencryption.fll is simalary to Cryptor.

Walter.
Walter
Saturday, August 18, 2007 1:56:11 PM (Central Daylight Time, UTC-05:00)
Hi Walter,

As I understand it, Cryptor has the ability to encrypt and decrypt VFP data on-the-fly at runtime (hooks into the disk IO of the VFP process). The vfpencryption71.fll does not currently support this feature (though I've been looking into it these past couple months). The vfpencryption71.fll supports a larger number of cyphers than cryptor and allows VFP devs to:

Encrypt/decrypt strings, binary data, and files on disk
Hash strings, binary data, files and records
CRC strings, binary data, files and records
Thursday, December 20, 2007 9:59:00 PM (Central Standard Time, UTC-06:00)
Craig,

Several of my apps are now using this FANTASTIC tool - and working flawlessly, of course!! If you find the opportunity, please consider re-compiling/re-publishing VFPEncryption80.FLL as well.

HAPPY HOLIDAYS and MANY MANY MANY THANKS!!!!!
Saturday, January 19, 2008 4:40:39 PM (Central Standard Time, UTC-06:00)
Hi Craig,

when i use the fll under windows 2000 i get an error message that the fll is invalid. Any ideas?

Thanks a lot

ramses
Ramses
Friday, January 25, 2008 9:45:44 AM (Central Standard Time, UTC-06:00)
Hi Craig,

Me^^ too receive error message running Window Server 2000.

Any solution ...?



TIA,

Patrick

patrick
Friday, January 25, 2008 6:41:48 PM (Central Standard Time, UTC-06:00)
Ramses and Patrick,

99.99% of the time the "invalid fll" error is caused by the fact that the required C runtimes are not present for the FLL. Using the Search feature of this blog you should find numerous places on this blog where I have addressed this issue. The problem is not an incompatibility with any of the Window's OS.

If, after having read and tried the solutions presented in this blog, you are still having problems, feel free to email me directly and I will do what I can to help you solve the issue.
Wednesday, April 30, 2008 5:05:21 PM (Central Daylight Time, UTC-05:00)
Hi Craig,

I really love your tool, it made it possible to create some nifty features in our application!
I'm having a problem now. The application is finally finished, and I'm testing the Installshield Express setup on a virtual machine (with Virtual Box). I keep getting the error that the .fll is invalid though. I did install the latest vcredist from the Microsoft site, but that doesn't help.
Any idea what else I could try?
Richard Daniels
Thursday, May 01, 2008 2:01:11 AM (Central Daylight Time, UTC-05:00)
Hi Richard,

If you are using vfpecnryption71.fll then include the 7.1 C run-time libraries (in System32 or in the same folder as the fll). If you are using vfpencryption.fll then include the 8.0 C run-time libraries. The invalid error you are getting is definitely because the appropriate runtimes are missing or your VFP app is unable to locate them along the path it searches.
Wednesday, August 27, 2008 10:43:01 PM (Central Daylight Time, UTC-05:00)
Hi Foxers!

I found the solution !!!
Copy the dll msvcp71.dll to windows\system32 (the file is incluse in VFP9 installer).
Or include the dll in install program.
Thanks Craig Boyd !!
Excelent tool!!!
Thiago Takehana
Monday, October 06, 2008 4:16:15 PM (Central Daylight Time, UTC-05:00)
Hi Craig,
I am doing tests with the function decrypt. When decrypt a string deliberately wrong a dll cause an exception... I expected instead that the result was an empty string or a False value.
What it's wrong?

Thank's!
Riccardo
Name
E-mail
(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, b, blockquote@cite, em, i, strike, strong, sub, super, u)  

Enter the code shown (prevents robots):


 

Archive

<October 2008>
SunMonTueWedThuFriSat
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678