Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Table encryption in VFP 7? 2

Status
Not open for further replies.

mansii

Programmer
Oct 18, 2002
641
ID
Hi All!
In one of the so many threads (if I'm not mistaken) I read someone (I forgot weather it was Mike or Rick or someone else) stated that it was possible to perform a data encryption in VFP 7. He said that we could use _encrypt.vcx or something.

Mike? Was that you? Or Rick?
Would someone please tell me again about this? Peas...?

TIA.
 
Mansii,
There are a lot of ways to encrypt, or at least give the appearce of encrypting in any version of Fox. In some of the VFP versions, you have a couple of extra options.
I would, however, say this. If you have the need for very tough encryption, especially at the table level (entire table), than your best bet is a 3rd party product called Cryptor from Xitec. I use it extensively, and it is a *very* excellent tool. It's available from hallogram's website, I think around $399 US.
However, if you just need to make it so the average "joe" can't get a good look at your data, and you want to encrypt a column or two (especially where passwords are concerned), there are a couple of other ways that this can be done.
One way is to store the value as the checksum of a character string using SYS(2007). I would suggest storing this a field type Integer. This is a 4 digit field, that is capable of storing numbers up to over 4 billion. (255*255*255*255). So, if you wanted a password field, you could pass in something like: 'Scott1234' would yield 17691, which fits nicely into the integer type. You're not actually storing "Scott1234", but the checksum of that character string. Mixed case will return differing values as well, such as "SCOTT1234" yields 27961. This is a very efficient way to "Store" values that you need to check against.
However, this is not good for other things, where you simply want to make something unavailable to the user, like say the contents of someone's address. Contained below is an encryption routine that I have created and used many times:

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This function receives a character value of no more than 49 characters long, and
* creates an encryption string for the value. It can also receive an encrypted string,
* and reverse the process to return the unencrypted value.
*
* M.CHARSTRING = Database character string to Encrypt/Decrypt.
* M.OFFSET = String offset determined by the first character of the string.
* This adds an additional measure of security to the encryption
* process.
* M.CODE = 220 character random ASCII string.
* M.CONVERSION = Encrypted/Decrypted converted characters.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

FUNCTION ENCRYPT

PARAMETERS lcCHARSTRING, lcCNVTTYPE
*
IF PARAMETERS() # 2
MESSAGEBOX('Invalid Number of Parameters. Please Correct this Problem before Trying Agian.',16,;
'Encryption Error')
RETURN
ENDIF
*
IF LEN(lcCHARSTRING) > 46
MESSAGEBOX('Value Too Large To Encrypt. Must Be 46 Characters Or Less.',16,;
'Encryption Error')
RETURN
ENDIF
*
lcCNVTTYPE = UPPER(lcCNVTTYPE)
lnCOUNT = 1
lcCONVERSION = ""
lnOFFSET = 11 - MIN(25,LEN(TRIM(lcCHARSTRING)))
lnINCREMENT = 0
*

lcCODE = "7l{ªÙz[qûL®÷ÁTUJP6 î£5È”²Å¿DÒy§MËåÝH.Öha*áë™›:­Ã˜ò,EW¥â¹Oƒù¦Õ¼Š/Î\Q³>|“" + ;
&quot;Gc×’Bv¢ÍŽ`—A‡r‚uf$CÞó(í_‘ºãd&æ½ñðnÜÇž´¡Ÿ†–8ø<Nšˆ9·úľbk#‰ì2€~çgï¬YÐt„wü'p&quot; + ;
&quot;jéà1m0o«eÊ4»õ}@þœÓßö¯èKZ‹©iÚýÉ!?êVØ+S^±ÔϤ)X]x=s3ÂÌ…FÀ-¸Ñô¶Æ°Œµ%;•¨ÛäRI&quot;
*
IF NOT lcCNVTTYPE $ 'E D'
MESSAGEBOX('Not a Valid Encryption Type',16,'Encryption Error')
RETURN
ENDIF
*
DO WHILE lnCOUNT <= LEN(TRIM(lcCHARSTRING))
IF lcCNVTTYPE = 'E'
lcCONVERSION = lcCONVERSION + ;
SUBSTR(lcCODE,ASC(SUBSTR(lcCHARSTRING, lnCOUNT,1))-lnOFFSET,1)
ELSE
lcCONVERSION = lcCONVERSION +;
CHR(lnOFFSET + AT(SUBSTR(lcCHARSTRING,lnCOUNT,1),lcCODE))
ENDIF
*
lnCOUNT = lnCOUNT + 1
IF lnINCREMENT = 4
lnINCREMENT = 0
lnOFFSET = lnOFFSET-3
ELSE
lnINCREMENT = lnINCREMENT + 1
lnOFFSET = lnOFFSET+lnINCREMENT
ENDIF
ENDDO
*
RETURN lcCONVERSION


I can actually quite safely post this here, and not compromise my own encryptions because I have changed the substitution table. (Which contains every character equiviaent for the decimal values from 1 to 255, also known as ASCII and Extended ASCII sets). You simply need to copy and past this function into your procedure file, and then call it. It is also self reversing, so passing in for example:

lcEncrypted = ENCRYPT('Scott1234','E')

will yield something like (though not exactly):
$ç8»Ñc%.h

lcEncrypted = ENCRYPT('SCOTT1234','E')

)apP;Ü&#9565;@&quot;

Passing then:

lcDecrypted = ENCRYPT(lcEncrypted,'D')
would reverse the encrypted value to:

Scott1234

You get the idea. This rotine will also encrypt spaces, so you can't tell where words break (if they do).

It is limited only in that you can not generate a string greater than 49 characters long. But, you can break long strings into pieces with a little code, since this algorithem does not effect the total length, you will alwyas get back the correct number of characters. (So, just pass it 49 character chunks, and whatever is left over when not equalling 49 characters.




Best Regards,
Scott

&quot;Everything should be made as simple as possible, and no simpler.&quot;[hammer]
 
mansii

In one of the so many threads (if I'm not mistaken) I read someone (I forgot weather it was Mike or Rick or someone else) stated that it was possible to perform a data encryption in VFP 7. He said that we could use _encrypt.vcx or something.

Other than the suggestion TheManiac made, you can use the _encrypt.vcx library to encrypt your tables. The is a sample of how to use it in the VFP &quot;solutions&quot;.
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first
 
Thank's Scott, for your very quick solution and your listing. But since my programming skill is not as good as yours, I have to read it again and again first... phew.. Actually, what I need is some explaination about _encrypt.vcx. I have tested the Cryptor from Xitech, and yes, so powerfull. Does _encrypt.vcx acts the same way as Cryptor?

Mike, I have opened the 'solutions' but I couldn't find any object closed to _encrypt.vcx or even stated in any procedures or objects. Would you please tell me where its location is?

Uh, yes, the first question goes to you too, Mike. :)

TIA.
 
mansii

The class on my system is _crypt.vcx (not _encrypt.vcx) locate in the FoxPro Foundation Class directory :
&quot;C:\Program Files\Microsoft Visual FoxPro 7\Ffc&quot;

The form is called &quot;crypto.scx&quot; located here:
&quot;C:\Program Files\Microsoft Visual FoxPro 7\Samples\Solution\Ffc&quot;

And in the &quot;Solutions&quot; application. It's under &quot;Foundation classes&quot;-> &quot;Add encryption to your applications&quot;.



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top