Encrypt tabel

schimanski

Well-Known Member
Licensed User
Longtime User
Hello!

Is there an easy way to encrypt a table file? If I use the XML-Table, every data can watch with the internet explorer.
And is it better to use CSV than XML for encrypt?

I have worked with the crypt-lib to encrypt and decrypt one password, but is that also the solution for a whole database?

regards from germany...
 

schimanski

Well-Known Member
Licensed User
Longtime User
Thanks, Erel! But I only use a very small table with 4 cols and 20 to 30 rows. I think it's not enough to use sql.

But I tried now to encrypt every cell with the following code:

B4X:
Sub Globals
  Dim string(0) As Byte, secret(0) As Byte 
  PassPhrase = "my key" 
end sub

Sub Encrypt
  For x=0 To Table1.RowCount-1
    For y=0 To table1.ColCount-1
         
       Data=Table1.Cell(Table1.ColName(y),x)
       string() = Bit.StringToBytes(Data,0,StrLength(Data)) 
       secret() = Crypto.Encrypt(PassPhrase, string()) 

       For i = 0 To ArrayLen(secret())-1 
         s = s & bit.DecToHex(secret(i))
       Next
       Table1.Cell(Table1.ColName(y),x) = s
    Next
  Next
End Sub

But only the first col will encrypt exactly, the other cells becomes longer and longer with each row. s="" doesn't help.:BangHead:

Could anyone see the problem?

regards from germany
 

schimanski

Well-Known Member
Licensed User
Longtime User
Here i a small example from my desktop-application:

The file Datenbank.txt must renamed into datenbank.xml.

If you close the application and saves the data, the encryt data becomes longer and longer. You can see the encrypt cells with the line msgbox(s).

Thanks and regards...
 

Attachments

  • Foxfinder Datenbank.sbp
    4.1 KB · Views: 182
  • Datenbank.txt
    2.2 KB · Views: 247

schimanski

Well-Known Member
Licensed User
Longtime User
Hello Erel, thanks for answer.

But s="" doesn't work, I have tried it before.
I add s="" in line 88 and show s in line 95 with msgbox(s).

After encrypt some cells, you see that 's' is always growing, but not for all cells. The first cell of a row will encrypt right, the second to fourth cell of the row grows up after some clicks.. I don't find the problem....
 

agraham

Expert
Licensed User
Longtime User
There are two problems.

First, as Erel says, there is a missing initalisation of s in the inner loop.

Second the Table is set to sort on the first column so as you encrypt and overwrite the first column the table resorts itself so you now encrypt already encrypted data.

You need to do something like this

SortCol = "Modul ASC"
Table1.TableSort (SortCol)

...

Table1.TableSort ("")
... ' do encrypt or decrypt stuff
Table1.TableSort (SortCol)
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…