Wednesday, August 31, 2005

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

Wednesday, August 31, 2005 9:03:42 AM (Central Daylight Time, UTC-05:00)  #    Comments [9]
Wednesday, August 31, 2005 10:38:28 AM (Central Daylight Time, UTC-05:00)
Hi,

thank you very much - this FLL is very useful.

There is currently just one problem with it - it is not possible to use this FLL beginning the version with HASH functions due to its dependancy on MSVCP70.DLL - DLL which is just in .NET framework. Is it really necessary to use this DLL?

Best regards,
Milan
Milan Kosina
Wednesday, August 31, 2005 6:24:21 PM (Central Daylight Time, UTC-05:00)
Craig,

Can you access HASH functions in advapi32.dll vs. msvcp70.dll?

I wonder if MSVCP70.DLL can be distributed without dependencies on other .NET DLL's? I did a quick google on this topic without learning whether this is possible or not.

Malcolm
Wednesday, August 31, 2005 6:34:45 PM (Central Daylight Time, UTC-05:00)
Milan and Malcolm,

I am looking into this and will be back with comments and perhaps a modified FLL.

To All,

Glenn found another bug (great work Glenn!). It has been fixed and a new version of the FLL has been uploaded. I think the FLL is really starting to stabilize. However, if you could download the latest version (I just put it up there minutes ago) and test it and provide feedback to me, I would really appreciate it.
Wednesday, August 31, 2005 6:35:57 PM (Central Daylight Time, UTC-05:00)
It appears that msvcp70.dll is an optional companion of msvcrt70.dll and, according to the discussion on this thread, can be distributed without any .NET dependencies.

http://aigamedev.com/Forum/viewtopic.php?p=158&sid=cbb2fe17ddd4431b3d13de4cf574bed1

Also note that there appears to be a msvcp71.dll that matches the msvcrt71.dll that gets distributed with VFP 9. Perhaps msvcp71.dll should be used instead of msvcp70.dll? (msvcp71.dll is a 500K DLL located in my system32 folder)

Malcolm
Wednesday, August 31, 2005 6:47:34 PM (Central Daylight Time, UTC-05:00)
The result is the same for me as previously :(

BTW I don't have MSVCP70.DLL in any normal folders+subfolders (Windows, "Microsoft Shared", "Microsoft Visual Studio .NET 2003"). I've Windows 2003 Server SP1.

Best regards,
Milan
Milan Kosina
Wednesday, August 31, 2005 6:49:53 PM (Central Daylight Time, UTC-05:00)
Sorry, one more comment - I've this DLL, but it is not on the set path, so it has to be copied to the same dir.

Little question: is it really necessary to use .NET DLL in FLL?

Best regards,
Milan
Milan Kosina
Wednesday, August 31, 2005 6:56:53 PM (Central Daylight Time, UTC-05:00)
Milan,

I'm not convinced that MSVCP70.DLL (MSVCP71.DLL) is a .NET specific DLL anymore than VFP 9's MSVCR71.DLL is a .NET DLL.

The only issues to be aware of (that I can think of) are that MSVCP7*.DLL should probably match its companion MSVCR7*.DLL of the same version and that MSVCP7*.DLL (~500K) adds about 130K of overhead to an application's distribution when compressed as part of a setup.

Malcolm
Wednesday, August 31, 2005 8:14:03 PM (Central Daylight Time, UTC-05:00)
My idea that it is .NET DLL is based on (thanks to Martin Jindra):
http://www.liutilities.com/products/wintaskspro/dlllibrary/msvcp70/

Milan
Milan Kosina
Saturday, October 01, 2005 8:34:49 AM (Central Daylight Time, UTC-05:00)
According to http://support.microsoft.com/default.aspx?scid=kb;en-us;154753 there must be reference to the new IOStream or the STL somewhere in the project. I may still look into this, however starting with VS 2003, Microsoft is no longer shipping the older IOStream libraries.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_c_run.2d.time_libraries.asp

So, it is perhaps inevitable that this encryption library will require msvcpxx.dll. In fact, I've already rebuilt the library using VS 2003 (VC++7.1), and will be posting that version along with the runtimes (msvcrt and msvcp). I think the point is a bit moot, though I sympathize with having to include an additional runtime library in the installation sets in order to use it.
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

<November 2008>
SunMonTueWedThuFriSat
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456