FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour encrypting dbf files
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: encrypting dbf files
Posted: Tue Oct 01, 2013 03:38 PM
Enrico,

As far as I know, SIXCDX is included in xHarbour's DBFCDX.


That was the conclusion that I came to. Probably Hunter has not tried it recently and thus his statement that you have to use the Six driver to encrypt.

James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: encrypting dbf files
Posted: Tue Oct 01, 2013 04:54 PM
James,

James Bott wrote:Enrico,

As far as I know, SIXCDX is included in xHarbour's DBFCDX.


That was the conclusion that I came to. Probably Hunter has not tried it recently and thus his statement that you have to use the Six driver to encrypt.

James


I agree. Anyway, I would like to know how to get it to work with memo fields too...

EMG
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: encrypting dbf files
Posted: Tue Oct 01, 2013 09:40 PM

Enrico,

I am unable to encrypt memo files too.

Hunter,

Are you perhaps using the original SIX library instead of the xHarbour one?

Maybe memo field encryption has not yet been implemented in the xHarbour version.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: encrypting dbf files
Posted: Wed Oct 02, 2013 02:37 PM
Six Driver NG Guide online

http://www.ousob.com/ng/six3/index.php

From the section on SX_encrypt() (Note that this encrypts a string and is not the same as SX_dbfencrypt() but we can probably assume that this uses the same encryption method).
http://www.ousob.com/ng/six3/ng25e56.php

------------
Description: Sx_Encrypt() and it related function Sx_Decrypt() provide
an easy way to integrate data security to a system. The
encryption engine provides security through the use of a
64-bit (8 byte) security code and multi-adaptive computa-
tion. Multi-adaptive computation ensures a wide uniqueness
within the outputted encrypted string. If a string of all
blanks were encrypted you would see a wide distribution of
characters. This ensures a reasonable amount of security
at a small speed penalty.

Of course, the best way to protect your data is to keep it
away from those who shouldn't have access to it. Protect
your passwords, and don't store them in .DBF files.

This encryption/decryption method is _not_ DES (Data
Encryption Standard) compliant, so it can be used in
programs distributed both in the US and Overseas.


OK, 64bit encryption is not very good, but it will prevent casual users from getting into the DBFs. It would be nice to have the option of higher level encryption but there would also be a speed penalty.

James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: encrypting dbf files
Posted: Wed Oct 02, 2013 02:47 PM

More on encrypted memo fields:

This SIX driver apparently doesn't work with memo files. However, I think we can come up with a workaround. You will need to do something like the following.

1) Create a DBF without a memo field (this can be encrypted using SX_DBFENCRYPT(). There needs to be a primary-key field containing a unique non-blank value. Use the primary key field to link to another DBF containing only a memo field.

2) Create a subclass of TDatabase (or TData) and write new save() and load() methods. In these methods you need to automatically lookup the memo field associated with the original primary-key. Then encrypt or decypt the memo field data as needed.

The above will make everything transparent and automatic.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: encrypting dbf files
Posted: Wed Oct 02, 2013 06:13 PM

Regarding my previous message, you will also need to add new Append() and Delete() methods. These will need to add and delete records from both files.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 723
Joined: Tue Sep 04, 2007 08:45 AM
Re: encrypting dbf files
Posted: Sat Oct 05, 2013 05:19 AM

James, Enrico:

I do encrypt my DBFs with a 16 bit Clipper utility program using the SIX driver. Memos do encrypt. In 32 bit you can encrypt the memo field before storing it with the Sx_encrypt (cPassword) function and that's it (in case that the memo fields does not get encrypted).

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: encrypting dbf files
Posted: Sat Oct 05, 2013 06:57 AM
Hunter,

HunterEC wrote:James, Enrico:

I do encrypt my DBFs with a 16 bit Clipper utility program using the SIX driver. Memos do encrypt. In 32 bit you can encrypt the memo field before storing it with the Sx_encrypt (cPassword) function and that's it (in case that the memo fields does not get encrypted).


Sorry, I didn't get it working... :-)

EMG
Posts: 723
Joined: Tue Sep 04, 2007 08:45 AM
Re: encrypting dbf files
Posted: Sat Oct 05, 2013 09:36 AM

Enrico:

If you can email me (morenoec2007 at hotmail dot com) your program or a sample program and your DBFs, I'll give it a try. Thank you.

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: encrypting dbf files
Posted: Sat Oct 05, 2013 09:45 AM
Hunter,

HunterEC wrote:Enrico:

If you can email me (morenoec2007 at hotmail dot com) your program or a sample program and your DBFs, I'll give it a try. Thank you.


Here it is:

Code (fw): Select all Collapse
FUNCTION MAIN()

    DBCREATE( "MYTEST", { { "TEST1", "C", 35, 0 },;
                          { "TEST2", "M", 10, 0 } } )

    USE MYTEST EXCLUSIVE

    APPEND BLANK

    REPLACE FIELD -> test1 WITH "Test1"
    REPLACE FIELD -> test2 WITH "Test2"

    CLOSE

    USE MYTEST EXCLUSIVE

    ? SX_DBFENCRYPT( "EMAG" )

    ? SX_ENCRYPT( "EMAG" )

    ? SX_TABLETYPE()

    CLOSE

    INKEY( 0 )

    RETURN NIL


EMG
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: encrypting dbf files
Posted: Sat Oct 05, 2013 03:22 PM
Hunter,

I do encrypt my DBFs with a 16 bit Clipper utility program using the SIX driver. Memos do encrypt. In 32 bit you can encrypt the memo field before storing it with the Sx_encrypt (cPassword) function and that's it (in case that the memo fields does not get encrypted).


I am not sure I understand what you are saying. Are you confirming that 32bit FWH programs cannot encrypt DBF files containing a memo field?

Yes, you can encrypt a memo field using SX_encrypt() however you cannot cannot create the typical DBF with a memo field as the entire DBF cannot be encrypted. So as I mentioned in previous messages, you have to create the main DBF WITHOUT a memo field and another DBF containing only the memo field and do the linking via code and encrypting/decrypting using Sx_encrypt() and Sx_decrypt() which considerably complicates things.

Do you know why memo field encryption was never implemented in 32bits?

Regards,
James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: encrypting dbf files
Posted: Sat Oct 05, 2013 03:33 PM
James,

James Bott wrote:Do you know why memo field encryption was never implemented in 32bits?


It was a Przemek decision. :-)

EMG
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: encrypting dbf files
Posted: Sat Oct 05, 2013 06:20 PM
Enrico,

It was a Przemek decision.


I wonder why. It seems that it would be simple to implement since the encryption/decryption code is already working. Maybe there is some other technical issue...

Maybe some user requests would get him motivated.

James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: encrypting dbf files
Posted: Sun Oct 06, 2013 03:25 PM
To All

There functions have served me well over the years .. I copied this ( public domain ) code from an old Clipper Tools book some time ago and have modified it from time to time.

As you can see .. I added msginfo() to test the values and rem'd them out. Feel free to try them for yourselves. Please note that this code offsets the data by one character at the beginning and you may need to adjust the width of your variables.

Rick Lipkin

Code (fw): Select all Collapse
//------------------------
Func ENCRYPT( TO_DO )

Local PadBack,Done,Qaz

PadBack := Len(To_Do)
*msginfo( "Padback" )
*msginfo( PadBack )
Done    := " "

TO_DO := ALLTRIM(TO_DO)

FOR QAZ := LEN(TO_DO) to 1 STEP -1
    DONE := DONE + CHR(ASC(SUBSTR(TO_DO, QAZ, 1)) + 104)
NEXT

*MsgInfo( "In Encrypt" )
*MsgInfo( Done )
*msginfo( Len( Done ))

RETURN( Fill_Out( Done, PadBack ))

//--------------------
Func DENCRYPT( TO_DO )

LOCAL PADBACK := LEN(TO_DO), DONE := " ", QAZ
TO_DO := ALLTRIM(TO_DO)

FOR QAZ := LEN(TO_DO) to 1 STEP -1
    DONE := DONE + CHR(ASC(SUBSTR(TO_DO, QAZ, 1)) - 104)
NEXT

RETURN( FILL_OUT(DONE, PADBACK))

//----------------------
Func FILL_OUT( Done, PadBack )

*   MsgInfo( "In Fill_Out Pcount")
*   msginfo( pcount())

*   Msginfo( len( done ))

IF PCOUNT() = 1
   PadBack := 80
ELSE

*   msginfo( "Initial PadBack" )
*   msginfo(  PadBack )

   IF TYPE("PadBack") = "C"
      PadBack := VAL(PadBack)
   ENDIF

   *   PadBack := IIF(PadBack <= 1, 80, PadBack)
   If PadBack >= 1
   Else
      PadBack := 80
   Endif

  * PadBack := IIF(PadBack < 1, 80, PadBack)
*   msginfo( "End PadBack")
*   msginfo( PadBack )

ENDIF

*msginfo( "if PadBack <= len(Done)")
*msginfo( PadBack)
*msginfo( len(Done))

IF PadBack <= LEN(Done)
*   Msginfo( "Return Done")
*   Msginfo( Done )
*   msginfo( len(done ))
   RETURN(Done)
ENDIF

RETURN(Done + SPACE(PadBack - LEN(Done)))
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: encrypting dbf files
Posted: Sun Oct 06, 2013 03:55 PM
Rick,

Rick Lipkin wrote:To All

There functions have served me well over the years .. I copied this ( public domain ) code from an old Clipper Tools book some time ago and have modified it from time to time.


Thank you. We are discussing an encrypting system at RDD level here. It already exists but unfortunately it doesn't work with memo fields.

EMG