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: Wed Sep 25, 2013 08:30 PM
Jeff,

I use the free ADS encryption. It encrypts the entire file.


So does the Six RDD. I was responding to Jack's request to just encrypt a couple of fields. I don't know if the Six RDD will do this, but I don't know why it would be useful either.

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 Sep 25, 2013 08:40 PM
Hunter,

I just reread this:

(x)Harbour supports three functions to handle encryption / decryption transparently:
1. Sx_DBFencrypt (cPassword) - encrypts all records in database file.
2. Sx_DBFdecrypt () - decrypts all records in database file.


This leaves me wondering, are there functions to encrypt and decrypt a record (or field)? I can't see how decrypting an entire DBF would be practical in an application.

Are the SX functions documented somewhere online, or is there a downloadable manual?

What would be really nice is just something like SET ENCRYPTION ON, then using the database as you normally would. Is this possible? Or, better yet, if the Six RDD could automatically detect if the file was encrypted, and then automatically (and transparently) encrypt and decrypt the data as needed. Now that would that be nice!

However, if we had the capability to encrypt and decrypt records, then we could build the encryption/decryption into a database class so it would all be transparent.

James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 368
Joined: Sun May 31, 2009 06:25 PM
Re: encrypting dbf files
Posted: Thu Sep 26, 2013 01:46 AM

Most of the SX functions are documented in the SIX3.NG. It´s a 500kb file. I have it but I´m not sure it´s allowed to publicly share it. If yes I can upload it to my FTP server, if not I can send as email attachment. Just let me know.

Regards,



André Dutheil

FWH 13.04 + HB 3.2 + MSVS 10
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: encrypting dbf files
Posted: Fri Sep 27, 2013 12:05 PM
James,

James Bott wrote:What would be really nice is just something like SET ENCRYPTION ON, then using the database as you normally would. Is this possible? Or, better yet, if the Six RDD could automatically detect if the file was encrypted, and then automatically (and transparently) encrypt and decrypt the data as needed. Now that would that be nice!


Please have a look at Marco's message at the start of this thread. :-)

EMG
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: encrypting dbf files
Posted: Fri Sep 27, 2013 04:37 PM
Enrico,

Please have a look at Marco's message at the start of this thread.


Hmm, I guess you are telling me, no there are no record or field level decryption Six functions?

As I mentioned, it seems impractical to decrypt all DBFs when running a program. When it the program is multi-user, it gets a lot more complicated as the files need only to be decrypted when the first user runs the program. If the DBFs are large then it could take 10 minutes or more to decrypt the files. You would have to move all DBFs across the network twice--once to read and once to write.

Then when the last user exited the program all the files would then have to encrypted again and all the decrypted files would have to be securely erased. This would take even longer than opening the program.

While all the files are decrypted, they are vulnerable to unsecure access. Anyone could open the files and copy them.

Record or field level decryption seems to be the only feasible method of working with encrypted databases. So, I guess the Six driver is out and FW's own encrypt/decrypt functions are in. Since FW's functions only work with character fields, then we need to keep track of fieldtypes in a datadictionary file so we can convert the character data to the proper fieldtype on-the-fly.

Ah, the kingdom for SET ENCRYPTION ON.

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: Fri Sep 27, 2013 05:15 PM

James,

I think you have not read Marco's message carefully. Please do it. :-)

EMG

Posts: 723
Joined: Tue Sep 04, 2007 08:45 AM
Re: encrypting dbf files
Posted: Sat Sep 28, 2013 08:49 AM

James, Enrico:

The Sx_DBFencrypt & Sx_DBFdecrypt functions are used in a separate program, as the one I posted earlier in this post's thread. Afterwards you just open your DBF files and call the Sx_SetPass (cPassWord) function. The SIx driver handles everything transparently, meaning that you DON'T have to decrypt / encrypt any record at all before / after processing. It's done all automatically. As Antonio posted in one of my posts, all drivers (DBFCDX, DBFNTX) on Harbour supports these functions.

As to how to find out if a DBF is encrypted, you can use the Sx_TableType() and it will return a. 1 - for non encrypted b. 2 - encrypted. You can also encrypt the file a couple of times, just make sure you decrypt it in reverse order.

This function encrypts the whole record without the need to set all field types as character ones. It is not possible to encrypt just a couple of fields only. As James pointed out, it will be useless, better to encrypt all data fields.

Hope this clarifies a couple of questions.

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: encrypting dbf files
Posted: Sat Sep 28, 2013 10:54 AM
HunterEC,

I'm trying the following sample:

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

    USE MYTABLE EXCLUSIVE

    ? SX_DBFENCRYPT( "EMAG" )

    ? SX_TABLETYPE()

    INKEY( 0 )

    RETURN NIL


It prints: .F. and 1. What am I missing?

EMG
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Re: encrypting dbf files
Posted: Sun Sep 29, 2013 02:43 AM

Hi.

By simply changing to ADS rdd, you get to use their encryption functions on free .dbf tables as well as data dictionary bound tables -- and it is all very well documented on the help file.

Reinaldo.

Posts: 723
Joined: Tue Sep 04, 2007 08:45 AM
Re: encrypting dbf files
Posted: Sun Sep 29, 2013 05:48 AM
Enrico:

For encryption / decryption via the Sx_DBFencrypt() and Sx_DBFdecrypt() you have to open the DBF with the SIX driver. Afterwards you can keep using the DBFCDX or DBFNTX one. This is due to the fact that these function changes one byte at the DBF header that the Sx_TableType() inspects (first byte). That is the reason that I use a separate tool for encrypting / decrypting DBFs.
Code (fw): Select all Collapse
    FUNCTION MAIN()

        USE MYTABLE EXCLUSIVE VIA "SIX"   <--- AFTER THIS SX_TABLETYPE() WILL RETURN A 2

        ? SX_DBFENCRYPT( "EMAG" )

        ? SX_TABLETYPE()

        INKEY( 0 )

        RETURN NIL
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: encrypting dbf files
Posted: Sun Sep 29, 2013 07:13 AM
HunterEC,

HunterEC wrote:For encryption / decryption via the Sx_DBFencrypt() and Sx_DBFdecrypt() you have to open the DBF with the SIX driver.


Sorry, no changes I'm still missing something... :-)

Code (fw): Select all Collapse
REQUEST SIXCDX


FUNCTION MAIN()

    USE POLIZZE EXCLUSIVE VIA "SIXCDX"

    ? SX_DBFENCRYPT( "EMAG" )

    ? SX_TABLETYPE()

    INKEY( 0 )

    RETURN NIL


EMG
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: encrypting dbf files
Posted: Sun Sep 29, 2013 07:19 AM
I also tried this but no lack:

Code (fw): Select all Collapse
#include "Hbsix.ch"


REQUEST SIXCDX


FUNCTION MAIN()

    USE POLIZZE EXCLUSIVE VIA "SIXCDX"

    ? SX_DBFENCRYPT( "EMAG" )

    ? SX_TABLETYPE()

    INKEY( 0 )

    RETURN NIL


EMG
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: encrypting dbf files
Posted: Sun Sep 29, 2013 03:36 PM

Hunter,

OK, I got SIX encryption working. Decrypting on the fly. I love it! This is going to be really useful.

Do you know what form of encryption is being used? I'm sure my customer's are going to want to know.

Regards,
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: Sun Sep 29, 2013 03:39 PM

Enrico,

It seems to be really transparent. You don't even need the REQUEST or the VIA.

Are you sure you are starting with an unencrypted file?

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: Sun Sep 29, 2013 03:43 PM
James,

James Bott wrote:Are you sure you are starting with an unencrypted file?


Of course. :-)

EMG