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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Encrypting a field

Status
Not open for further replies.

markg30

Programmer
Aug 2, 2000
4
0
0
US
I am running FPD 2.6 and I need to be able to encrypt/decrypt certain fields in a database at runtime using DES encrytion.&nbsp;&nbsp;Does anyone know of a PLB or BIN to allow me to do this?&nbsp;&nbsp;I have downloaded 3rd party DES encrytion libraries for C and tries to use them in my own PLB using the FoxPro LCK, but the encrytion functions crash FoxPro when then are called.<br><br>Thanks
 
<FONT FACE=monospace>Will these 2 function help?&nbsp;&nbsp;they only work on strings so you will have to convert other field types to a string before playing with it.<br><br><br>*/***************************************************************************<br>*/Program&nbsp;&nbsp;&nbsp;: function CODEIN<br>*/System&nbsp;&nbsp;&nbsp;&nbsp;:<br>*/Purpose&nbsp;&nbsp;&nbsp;: Scrambles a string into an unreadable form<br>*/Syntax&nbsp;&nbsp;&nbsp;&nbsp;: = CodeIn(Str,CodeSeed)<br>*/Returns&nbsp;&nbsp;&nbsp;: String<br>*/Parameter : String - Str - The String to Be Scrambled<br>*/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: Integer - Seed - Number to offset the asc code by<br>*/Defaults&nbsp;&nbsp;: None<br>*/Requires&nbsp;&nbsp;: None<br>*/Changes&nbsp;&nbsp;&nbsp;: Nothing<br>*/Internal Calls : None<br>*/External Calls : None<br>*/Version&nbsp;&nbsp;&nbsp;: 1.0<br>*/Dated&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: 02/03/1989<br>*/Written By: David W. Grewe<br>*/***************************************************************************<br>*& Utility - Security<br>*/***************************************************************************<br>*/ Record Of Change<br>*/<br>*/***************************************************************************<br>parameters P_STR, P_SEED<br>private P_STR, P_SEED<br>private L_PARA, L_LEN, L_CODEIN, L_PLACE<br>L_PARA = parameters()<br>do case<br>case L_PARA &lt; 1 .or. type('P_Str') # 'C'<br>&nbsp;&nbsp;wait window &quot;Function L_CodeIn, Needs To Be Passes A String To Code&quot;<br>&nbsp;&nbsp;return &quot; &quot;<br>case L_PARA &lt; 2 .or. type('P_Seed') # &quot;N&quot;<br>&nbsp;&nbsp;P_SEED = 10<br>endcase<br>*******<br>P_SEED = iif(P_SEED &gt; 20, 17, P_SEED) + 95<br>P_STR = trim(P_STR)<br>L_LEN = len(P_STR)<br>L_CODEIN = ''<br>*******<br>***&nbsp;&nbsp;encryption routine<br>*******<br>for I = 1 to L_LEN<br>&nbsp;&nbsp;L_PLACE = asc(substr(P_STR,I,1)) + P_SEED - I<br>&nbsp;&nbsp;L_CODEIN = L_CODEIN + chr(L_PLACE)<br>endfor<br>******<br>release P_STR, P_SEED, L_PARA, L_LEN, L_PLACE<br>return L_CODEIN<br><br>*/***************************************************************************<br>*/Program&nbsp;&nbsp;&nbsp;: function CODEOUT<br>*/System&nbsp;&nbsp;&nbsp;&nbsp;:<br>*/Purpose&nbsp;&nbsp;&nbsp;: Unscrambles A string, Scrambled with Function CodeIn, <br>*/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: back to a readable form<br>*/Syntax&nbsp;&nbsp;&nbsp;&nbsp;: = CodeOut(Str,Seed)<br>*/Returns&nbsp;&nbsp;&nbsp;: String<br>*/Parameter : String - Str - The String to Be UnScrambled<br>*/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: Integer - Seed - Number To Offset The AscCode By(must be the same as Codein)<br>*/Defaults&nbsp;&nbsp;: None<br>*/Requires&nbsp;&nbsp;: None<br>*/Changes&nbsp;&nbsp;&nbsp;: Nothing<br>*/Internal Calls : None<br>*/External Calls : None<br>*/Calls&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: <br>*/Version&nbsp;&nbsp;&nbsp;: 1.0<br>*/Dated&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: 02/03/1989<br>*/Written By: David W. Grewe<br>*/***************************************************************************<br>*& Utility - Security<br>*/***************************************************************************<br>*/ Record Of Change<br>*/<br>*/***************************************************************************<br>parameters P_STR, P_SEED<br>private all like P_*, L_*<br>L_PARA = parameters()<br>do case<br>case L_PARA &lt; 1 .or. type(&quot;P_Str&quot;) # &quot;C&quot;<br>&nbsp;&nbsp;wait window &quot;Function L_CodeOut, Needs To Be Passes A String To UnCode&quot;<br>&nbsp;&nbsp;return &quot; &quot;<br>case L_PARA &lt; 2 .or. type(&quot;P_Seed&quot;) # &quot;N&quot;<br>&nbsp;&nbsp;P_SEED = 10<br>endcase<br>P_SEED = iif(P_SEED &gt; 20, 17, P_SEED) + 95<br>P_STR = trim(P_STR)<br>L_LEN = len(P_STR)<br>L_CODEOUT = &quot;&quot;<br>*********************<br>***&nbsp;&nbsp;decoding routine<br>*********************<br>for I = 1 to L_LEN<br>&nbsp;&nbsp;L_PLACE = asc(substr(P_STR,I,1)) - P_SEED + I<br>&nbsp;&nbsp;if L_PLACE &lt; 32 .or. L_PLACE &gt; 128<br>&nbsp;&nbsp;&nbsp;&nbsp;wait window &quot;The string was not Scrambled with Function CodeIn&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;return &quot; &quot;<br>&nbsp;&nbsp;else<br>&nbsp;&nbsp;&nbsp;&nbsp;L_CODEOUT = L_CODEOUT + chr(L_PLACE)<br>&nbsp;&nbsp;endif<br>endfor<br>******<br>return L_CODEOUT<br></font><br><br><br>here is a sample routine on using them&nbsp;&nbsp;The VARMEM.DAT is just a dbf renamed and the VARMEM.DIF is a IDX renamed.&nbsp;&nbsp;Figured if the person breaking into the system knew it used DBF's and CDX's the DAT and DIF would help delay the action<br><br><FONT FACE=monospace><br>*/***************************************************************************<br>*/Program&nbsp;&nbsp;&nbsp;: Function varaccs<br>*/System&nbsp;&nbsp;&nbsp;&nbsp;:<br>*/Purpose&nbsp;&nbsp;&nbsp;: Fills / changes the F_ variables passed to it from the information in the Network Database<br>*/Syntax&nbsp;&nbsp;&nbsp;&nbsp;: Do UserFind<br>*/Returns&nbsp;&nbsp;&nbsp;: Nothing<br>*/Parameter : Nothing<br>*/Default&nbsp;&nbsp;&nbsp;: Nothing<br>*/Requires&nbsp;&nbsp;: A Database Named Network and the uc* Memvars previously declaired public<br>*/Calls&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: <br>*/Version&nbsp;&nbsp;&nbsp;: 1.0<br>*/Dated&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: 02/04/1989<br>*/Written By: David W. Grewe<br>*/***************************************************************************<br>*& Utility-Security<br>*/***************************************************************************<br>*/ Record Of Change<br>*/ <br>*/***************************************************************************<br>parameters P_NetName<br>if parameters() # 1<br>&nbsp;P_Netname = ucNetName<br>endif<br>***********************<br>on error quit<br>L_Alias = alias()<br>if used(&quot;VARMEM&quot;)<br>&nbsp;select VARMEM<br>else<br>&nbsp;select 0<br>&nbsp;use VARMEM.DAT alias VARMEM<br>endif<br>set index to VARMEM.DIF<br>*<br>* Get the new user information<br>*<br>set exact on<br>P_NetName = codein(P_NetName)<br>Seek P_NetName<br>L_passback = .f.<br>if found()<br>&nbsp;ucNetName&nbsp;&nbsp;= alltrim(codeout(VARMEM.ID))<br>&nbsp;ucPassWord = alltrim(codeout(VARMEM.FILE))<br>&nbsp;unSecurity = val(codeout(VARMEM.TYPE))<br>&nbsp;ucDrive&nbsp;&nbsp;&nbsp;&nbsp;= iif(codeout(VARMEM.DRIVE) = &quot; &quot;, &quot;C&quot;, codeout(VARMEM.DRIVE))+ &quot;:&quot;<br>&nbsp;ucPerson&nbsp;&nbsp;&nbsp;= substr(codeout(VARMEM.NAME), 1, at(&quot; &quot;,codeout(VARMEM.NAME))-1)<br>&nbsp;ucTitle&nbsp;&nbsp;&nbsp;&nbsp;= alltrim(codeout(VARMEM.TITLE))<br>&nbsp;F_Pdriver&nbsp;&nbsp;= alltrim(codeout(VARMEM.PRINTER))<br>&nbsp;L_passback = .t.<br>endif <br>set exact off<br>use<br>do errcall<br>if ! empty(L_Alias)<br>&nbsp;select (L_Alias)<br>endif<br>return l_passback<br></font> <p>David W. Grewe<br><a href=mailto:Dave@internationalbid.net>Dave@internationalbid.net</a><br><a href= > </a><br>
 
While I would think that would be good enough, my client insists on DES3 or equivalent encrytion.&nbsp;&nbsp;Any thoughts?
 
Sorry, Everything I've read on DES is file encryption.&nbsp;&nbsp;Have not seen anything on placing segments of a DES file inside another file.&nbsp;&nbsp;However I guess an encrypted file can be stored in a general field.<br><br>What file did you download and from where ? <p>David W. Grewe<br><a href=mailto:Dave@internationalbid.net>Dave@internationalbid.net</a><br><a href= > </a><br>
 
Actually, I just need to encrypt fields.&nbsp;&nbsp;for example, I need a foxpro function such as <br><br>en_text=ENCRYPT(param1, param2) (or DECRYPT)<br><br>where param1 is a key and param2 is the text string I want to encrypt.&nbsp;&nbsp;The only stipulation is that the encryption needs to be DES.<br><br>We are a telemarketing company, and one of our clients wants to provide us to encrypt credit card numbers so that casually browsing a database will not allow you to deciper these numbers with calling the DECRYPT function on with the key and the scrambled field as parameters.<br><br>I have downloaded various snippets of DES C code from various places, but most of them were written for UNIX systems and are parts of larger applications; it's been a royal pain trying to get the code to compile into a FoxPro PLB...&nbsp;&nbsp;I was hoping maybe someone had already done this for me.
 
THERE IS A SIMPLE WAY TO DO THE JOB,

*FUNCTION ENCRYPT
PARAMETER WHATTODO, THEFIELD
* WHATTODO = 1 -> ENCRYPT
* WHATTODO = 2 -> UN-ENCRYPT
* THEFIELD = TEXT TO BE HANDLE

DO CASE
CASE WHATTODO=1
THEFIELD=CHRTRAN(THEFIELD,'ABC...','&quot;#$%&amp;...')
* PUT IN ALL CHARACTERS
* YOU NEED TO ENCRYPT
CASE WHATTODO=2
THEFIELD=CHRTRAN(THEFIELD,'&quot;#$%&amp;...','ABC...')
* PUT IN ALL CHARACTERS
* YOU NEED UN-ENCRYPT
ENDCASE
RETURN(THEFIELD)


* NOTE THAT ALL YOU ARE DOING IS TRANSFORMING EACH CHARACTER INTO OTHER, THIS WAY OF ENCRYTION IS NOT THE MORE SAFELY BUT IT IS FAST AND WORKS GOOD ACCORDING YOUR NEEDS.

ANEIMANIS@HOTMAIL.COM

 
have you tried to save the data you want to encrypt to a file then run you c program on the file instead of local mem var? then you can simply append the field from the encrypted file. the c program might try to run wild as a call but it prob wont as an external run.

 
I have also looking for the same program that Infinitelo wants. I recently bumped into and downloaded some utilities, only that they are shareware. Since I did not have the money then, I held. Should you be interest, I can upload or send direct.

Maricus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top