Encoding DBF

835 views
Skip to first unread message

Krzysztof Stankiewicz

unread,
Apr 6, 2021, 3:26:19 PM4/6/21
to Harbour Users
Hello everyone
Database file encoding. Request for help.
I can't add an assembler source to Harbor.
originally it works with Clipper in the 16-bit version.


Today I need data encryption again and I don't know how to do it.
I think many will like it.
I only send the assembly language and description

Since I cannot attach a ZIP file, interested parties will be happy to send a working encoder (16-bit) to priv

FILESYS.ASM
KODOW.ASM
cipher_ang.txt

Krzysztof Stankiewicz

unread,
Apr 6, 2021, 3:28:20 PM4/6/21
to Harbour Users
Dodatek w języku polskim
cipher_pl.txt

Michael

unread,
Apr 7, 2021, 6:18:50 PM4/7/21
to Harbour Users
Cześć,
Kolego musisz zrezygnować z tego typu kodowania.
Ja też miałem wstawki w ASM u siebie i dla 32 bitów przerobiłem na HB lub C, ale lepsze miałem efekty w czystym HB (nie zawieszał się program)
Możesz użyć Advantage Database Server tam możesz bazę zakodować ale w inny sposób.
Moja propozycja jest taka aby stare bazy przekonwertować do normalnej postaci i zakodować jeszcze raz lub kodować same pola - pod HB i pod CL16 działa u mnie tak samo kodowanie, niemniej jednak taki sposób kodowania musisz porzucić.


Pozdrawiam

Krzys Stank

unread,
Apr 7, 2021, 6:41:26 PM4/7/21
to harbou...@googlegroups.com
Witaj
Dzięki za opinie.
Ciekaw jestem twego przekonania że powinienem zapomnieć o takim rozwiązaniu.
Niewiem jakiego rozwiązania używałeś ale to działa rewelacyjnie.
Szyfruje w całości plik z którym pracujesz, zaglądając do niego z dowolnej przeglądarki oprócz nazwy i rozszerzenia nie jesteś w stanie rozpoznać czegokolwiek, struktura pliku jest nieczytelna.
Jeśli masz dostęp do 16 bitowego kompa prześle ci gotowca do analizy.
Żadnego wieszania spowalniania czy innych zachowań nawet na bardzo wolnym sprzęcie.


Krzysztof Stankiewicz

Wiadomość napisana przez Michael <michael2...@gmail.com> w dniu 08.04.2021, o godz. 00:19:


--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users

---
You received this message because you are subscribed to a topic in the Google Groups "Harbour Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/harbour-users/CovK9nEP3TQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to harbour-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-users/ad2832ea-c694-4f55-8fd6-fd0b717dec87n%40googlegroups.com.

Michael

unread,
Apr 8, 2021, 3:43:53 AM4/8/21
to Harbour Users

W tej chwili u siebie mam tak,że mam w 100 % zgodny kod Clipper i HB 3.2
Także wszystko co dopisuje działa z automatu na dwóch platformach.
Możesz dać to 16 bit. Domyślam się w którym miejscu masz tą wstawkę w ASM , być może mógłbyś to przepisać na C i połączyć z HB,
ale wydaje mi się to dość trudne do zeralizowania.

U mnie były i są cały czas wstawki w ASM, z tym ,że podczas kompilowania 16 bit zostają a podczas kompilowania 32 bit ta sama wstawka jest zamieniana na taką , którą rozumie HB.

Pozdrawiam Michał

Michael

unread,
Apr 8, 2021, 3:54:48 AM4/8/21
to Harbour Users


Jeśli umiesz tą funkcję podłączyć pod Clipperem bez ASM to moim zdaniem rokuje.

Pozdrawiam

Francesco Perillo

unread,
Apr 8, 2021, 6:03:25 AM4/8/21
to harbou...@googlegroups.com
Can you please post a summary of your mail exchange in english?

You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-users/fa3ad228-380e-455b-beff-5606192c7533n%40googlegroups.com.

Krzysztof Stankiewicz

unread,
Apr 8, 2021, 6:27:54 AM4/8/21
to Harbour Users
Sorry, FPRILLO
I have two programs to encrypt and decrypt a DBF database:
CIPHER.EXE encryption of the specified dbf file.
DECIPHER.EXE decrypt indicated dbf file.
Useful for working with external DBF browsers.

Additionally, two library blocks:
FILESYS.OBJ + FILESYS.ASM,
CODE.OBJ + CODE.ASM.

I used OBJ libraries in Clipper, program runtime was unchanged, even on poor quality hardware.
Everything works on a 16-bit system.

I would need someone to adapt ASEMBLER to Harbor.

I tried to upload the zipped files to the forum but it failed and I don't know how to do it.

Alex Strickland

unread,
Apr 8, 2021, 6:37:19 AM4/8/21
to harbou...@googlegroups.com

Hi

DBF files can be encrypted in Harbour:

    DBINFO(DBI_ISENCRYPTED)

    DBINFO(DBI_ENCRYPT, "mypassword")

    DBINFO(DBI_DECRYPT, "mypassword")

--

Regards

Alex

Krzysztof Stankiewicz

unread,
Apr 8, 2021, 6:50:40 AM4/8/21
to Harbour Users
Hello
DBINFO () encrypts the contents of the fields being saved.
The sources I suggest encrypt the entire file.
Preview example in scr.jpg file
scr1.jpg

Alex Strickland

unread,
Apr 8, 2021, 6:54:27 AM4/8/21
to harbou...@googlegroups.com

Hi

When I use it encrypts or decrypts the entire file.

--

Regards

Alex

Krzysztof Stankiewicz

unread,
Apr 8, 2021, 7:50:06 AM4/8/21
to Harbour Users
Hello
How we use KODSTART () and KODSTOP ()

the same principle as dbinfo ()

KODSTART ()

dbcreate ('test', {{'F1', 'C', 10,0}} ..) // creates an encrypted file.
dbusearea ('test') // opens the encrypted file
test -> (dbSetIndex (...)) // create encrypted index
test -> (dbappend ()) // adds a crypted blank field
test-> F1: = 'Hello' // puts the ciphertext into the field

the contents of the F1 field are decrypted and readable by the program
for browse () say and others

dbclosearea () // close the encrypted file

KODSTOP () // end of file encryption

dbusearea ('test') // trying to open the encrypted file returns a structure error

W.

unread,
Apr 8, 2021, 8:49:50 AM4/8/21
to Harbour Users
Należałoby napisać moduł szyfrowania używając Harbour VF API w stylu tego:

Tu przykładem jest kompresja a nie szyfrowanie, ale jest tam miejsce na implementacje analogiczną do "własnego" FILESYS w Clipperze.

DBINFO(DBI_ENCRYPT... nie szyfruje oczywiście struktury bazy ani też plików memo.

pozdrawiam,
w.

hmpaquito

unread,
Apr 8, 2021, 9:12:07 AM4/8/21
to Harbour Users
IMHO, 

Harbour encrypt fails because not encrypt dbf with memo fields and too content in index files.
Dbfs on Harbour is not compliance European's data security

Francesco Perillo

unread,
Apr 8, 2021, 9:14:45 AM4/8/21
to harbou...@googlegroups.com
I understand what you want to do but perhaps is better to follow a more standard harbour way of encrypting files, using code that everyone uses.

I browsed the code you sent and of course it is for "msdos", with the use of interrupts
		int	21h			; DOS Services  ah=function 42h
						;  move file ptr, cx,dx=offset
Just browsing, with no deep inspection, it seems that it replaces some internal routines used by clipper to do some actions on the files
and this is ok... but I won't be able to port it to Harbour in a more generic way... The "porter" should know the internals of how Harbour
writes to the filesystem and hook on these.
Harbour implements - as far as I understand - a layer for handling file system calls, in a standard "documented" way. It's called virtual 
file handles and you can modify, in C... it should not be really difficult

Francesco Perillo

unread,
Apr 8, 2021, 9:22:42 AM4/8/21
to harbou...@googlegroups.com

I don't read polish but this is a sample of the virtual file handle... I think that starting from this source code it would be possible to replace your asm code in harbour standard way and the feature may be available to all the platforms harbour supports. And it should take no more than a few hours since the code is almost all written....

You just need to reverse engineering the obfuscation code of your asm... or you can implement another one.

Finally, harbour implements a way to specify file by file which handle to use, for example you can usa a ram based disk opening "mem:file.txt"... mem: is registered to be handled by a specific handler... so you may create a "kod:" handler and only the files opened in that way will be crypted/decrypted in real time.




On Thu, Apr 8, 2021 at 2:49 PM W. <wyle...@gmail.com> wrote:
Należałoby napisać moduł szyfrowania używając Harbour VF API w stylu tego:

Francesco Perillo

unread,
Apr 8, 2021, 9:31:08 AM4/8/21
to harbou...@googlegroups.com
Yes, in this case I decided to force a crypt using external functions:
k := hb_blowfishKey( "crypt-key" )
...
hL := hb_Deserialize( hb_blowfishDecrypt( k, FIELD->XYZ ) )
...
REPLACE XYZ    WITH hb_blowfishEncrypt( k, hb_Serialize( { "L1" => mL1, "L2" => mL2, "L3" => mL3, "L4" => mL4 } ) )

Don't mind I store an deserialized hash... you can encrypt the full string.

Perhaps it would be possible to implement the encrypt/decrypt in a USRRDD but I don't know if we can intercept a call to the writing of a memo field.




hmpaquito

unread,
Apr 8, 2021, 9:35:02 AM4/8/21
to Harbour Users

Michael Poland

unread,
Apr 11, 2021, 5:14:12 PM4/11/21
to harbou...@googlegroups.com
Daliście rade ? Moim zdaniem w prosty sposób to nie jest możliwe.
I think so this is impossible.

Best Redgards

Francesco Perillo

unread,
Apr 11, 2021, 5:39:43 PM4/11/21
to harbou...@googlegroups.com
today I spent a few hours implementing a very very simple encryption, XOR based, virtual file system.

I only tested a little bit with memowrit and memoread.

the scope is not crypting data (xor is too easy to break) but to avoid users to open dbf files with editors or excel...

i will test it more later this week

--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users

---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.

Ivanil Marcelino

unread,
Apr 12, 2021, 2:54:12 PM4/12/21
to harbou...@googlegroups.com
Just commenting.
I remember a file encryption methodology similar to that back in the 95s, it was a password file.
When the program ´s open, we dropped the application and the password file was ready to be opened with the DBU. When the file opened in shared mode was easier, it was enough to copy while the application was open and all security was lost.
The ideal is to encrypt the data with a validation field:

data-> CRC: = HB_MD5 (STrZero (data-> Code, 6) +;
                                         Data-> program +;
                                         tTos (data-> validity) +;
                                         Data-> Password)

Any changes in the fields above, the CRC invalidates, so there is no use opening with the DBU or any other method to try to read, as the content is encrypted, copying a valid value from another code and pasting in the current one would also not resolve due to the relation the key;



--

Krzysztof Stankiewicz

unread,
Apr 13, 2021, 4:49:48 AM4/13/21
to Harbour Users
Hello
Unfortunately I am not able to make any appointments in Harbor.
Someone else would have to do it.
I've been browsing the Harbor Sources and can't find a place to change.
The byte-shift encoding of the whole file is good, maybe it will find its creator one day.

Today, thanks to everyone for the tips.

For today, there remains almost the same good method:
DBINFO (DBI_ISENCRYPTED)

Krzysztof Stankiewicz

unread,
Apr 13, 2021, 7:20:07 AM4/13/21
to Harbour Users
Hello everyone
Does anyone have an example of use
    DBINFO(DBI_ISENCRYPTED)
    DBINFO(DBI_ENCRYPT, "mypassword")
    DBINFO(DBI_DECRYPT, "mypassword")
Preferably two files, one encoded the other not.
I will be grateful

ivanil.m...@gmail.com

unread,
Apr 13, 2021, 8:24:30 AM4/13/21
to Harbour Users
Begin copy group <HARBOUR MINIGUI > Grigory
========================
para Harbour Minigui
Hello Krzysztof,

The Harbour compiler hve the encryption feature on board.

Please take a look for the following example (was contributted by Przemek Czerpak):

#include "dbinfo.ch"
proc main()
field F1, F2
local aStru := {{"F1","C",10,0},{"F2","C",10,0}}, nRow
dbCreate( "tst", aStru )
use tst

/* set encryption key for new and modified records */
dbInfo( DBI_PASSWORD, "mypasswd" )

/* add few records */
dbAppend()
F1:="Hello"; F2:="World"
dbAppend()
F1:="Can you"; F2:="see it?"
dbcommit()

? "Let's see the table"
wait
nRow:=row(); dbgotop(); browse(); setpos(nRow+1,0)

? "Clear encryption key and see the table again"
wait 
dbInfo( DBI_PASSWORD, "" )
nRow:=row(); dbgotop(); browse(); setpos(nRow+1,0)

? "Restore valid encryption key then"
? "copy table to the new unencrypted one and browse it"
wait 

dbInfo( DBI_PASSWORD, "mypasswd" )
copy to tst2
use tst2 new
nRow:=row(); dbgotop(); browse(); setpos(nRow+1,0)
close all

? "Create new table then set encryption key for it and"
? "append records from other unencrypted table"
Wait

dbCreate( "tst3", aStru )
use tst3
dbInfo( DBI_PASSWORD, "mypasswd" )
append from tst2
nRow:=row(); dbgotop(); browse(); setpos(nRow+1,0)

? "That's all folks ;-)"
Wait

return

HTH,
Grigory

среда, 7 апреля 2021 г. в 01:04:15 UTC+3, Krzysztof Stankiewicz:

========================
END COPY

Gustavo González

unread,
Apr 13, 2021, 8:40:43 AM4/13/21
to harbou...@googlegroups.com
Hello!

The code work good, but if you add a MEMO field, the encrypt process dont work.

Any clues?

Thanks!

Nenad Batocanin

unread,
Apr 13, 2021, 8:44:19 AM4/13/21
to harbou...@googlegroups.com

Does anyone know which encryption method is used here?

 

Regards, NB

Krzysztof Stankiewicz

unread,
Apr 13, 2021, 8:58:45 AM4/13/21
to Harbour Users
Thank you Grygori for the second time.
I was hoping to get some new ideas from the guys.
An example (was contributted by Przemek Czerpak) is enough.

to encode the MEMO field I will use ??
This one or this one.
cBfKey: = hb_blowfishKey (<cPasswd>)
hb_blowfishEncrypt_CFB (<cBfKey>, <cText> [, <cInitSeed>])
hb_blowfishDecrypt_CFB (<cBfKey>, <cCipher> [, <cInitSeed>])
the encryption key needs a lot of memory.

hb_MD5Encrypt (<cText>, <cPasswd>) -> <cCipher>
hb_MD5Decrypt (<cCipher>, <cPasswd>]) -> <cText>
it seems more modest and doesn't remember the key.

W.

unread,
Apr 13, 2021, 9:02:58 AM4/13/21
to Harbour Users
It is SIXCDX/SIX3/Apollo RDD compatible encryption implemented by Przemysław Czerpak. It does not encrypt tables with MEMO fields, because Apollo had bugs with those, so they were not replicated.
Some info is available in ChangeLog.

2007-09-25 03:20 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
[...]
I still do not allow to encrypt tables with memo fields to not
replicate SIx3 bugs which may cause data corruption.

w.
wtorek, 13 kwietnia 2021 o 14:44:19 UTC+2 Nenad Batoćanin napisał(a):

r1....@live.com

unread,
Apr 13, 2021, 9:03:50 AM4/13/21
to Harbour Users
To All

I have been using these .dbf FIELD encryption and de-encryption .. uses the Ascii table values as its basis for the encryption .. 

//------------------------

Func ENCRYPT( 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 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( FILL_A, FILL_B )

IF PCOUNT() = 1
   FILL_B := 80
ELSE
   IF TYPE("FILL_B") = "C"
      FILL_B := val(Fill_B) //VAL(B)
   ENDIF
   FILL_B := IIF(FILL_B <= 1, 80, FILL_B)
ENDIF
IF FILL_B <= LEN(FILL_A)
   RETURN(FILL_A)
ENDIF

RETURN(FILL_A + SPACE(FILL_B - LEN(FILL_A)))


I must admit I got this from a Clipper book many years ago .. still works for me .. again, these functions encrypt\de-encrypt the data in the .dbf fields .. not the .dbf file itself.

Rick Lipkin

Francesco Perillo

unread,
Apr 13, 2021, 4:51:22 PM4/13/21
to harbou...@googlegroups.com
I completed the proof of concept of xoring all the accesses to the file system of a file. This solution also XOR the header of dbf and memo file.

The encryption is not strong, but in this way you can't load the file in excel or other tool.

The code is - I REPEAT - ONLY A PROOF OF CONCEPT NOT TO BE USED in production and has a serious flaw (it uses a buffer of 8000 bytes and there are no boundary cheks, I don't know how big the buffer should be.

Using the library is quite simple:
 dbCreate( "xor:dbxor", a )
 use ( "xor:dbxor" )

The encryption method can be changed, of course.

The code must be polished, probably also rewritten in a more harbour c style... if anybody is interested or wants to test it, please let me know.



Krzysztof Stankiewicz

unread,
Apr 13, 2021, 6:08:43 PM4/13/21
to Harbour Users

In the 1994 program, each reference to a file: 
Creation. 
Openly. 
Reading the structure. 
Reading the lines. 
Reading the field. 
Adding a poem. 
Notation of the poem. 
Field record. 
Close. 
It is with a byte shift of each character. 
The offset applies to all (characters / bytes) in the database file. 
The byte shift can be set from 1 to 255. 
You cannot read a file written in such a way other than with a specially made program.
 In encrypting 99% of databases, it is not about bank security. 
It is about blocking access to data by employees and voyeurs.

Francesco Perillo

unread,
Apr 19, 2021, 4:33:03 PM4/19/21
to harbou...@googlegroups.com
I attach the proof of concept library that encripts the whole file when it is written and deencripts when readed. It is highly based upon hbbz2io library and there are several things that should be updated and adapted.

It now uses XOR as the encryption method... it is not secure !!!

compile the lib with

hbmk2 hbxorio.hbp

cd test
hbmk2 test01.prg ..\libhbxorio.a

When the filename starts with XOR:name the XOR: is stripped and a new file handler is used.



hbxorio.zip
Reply all
Reply to author
Forward
0 new messages