Recent

Author Topic: Example of using encrypted sqlite databases for Lazarus needed.  (Read 5862 times)

wekwejt.com

  • New Member
  • *
  • Posts: 10
Example of using encrypted sqlite databases for Lazarus needed.
« on: October 14, 2021, 02:15:26 pm »
Hi guys!
I need to use encrypted sqlite database: sqlcipher or wxsqlite3 in my project but I have no experience with encryption sqlite and I can't find any example of that one.
I have created sqlcipher database with SQLiteStudio and I tried to connect with SQLdb components without succeed. Can someone help?

PierceNg

  • Sr. Member
  • ****
  • Posts: 369
    • SamadhiWeb
Re: Example of using encrypted sqlite databases for Lazarus needed.
« Reply #1 on: October 14, 2021, 02:43:52 pm »
1. What OS?

2. No matter the OS, SQLcipher requires its own dll/so/dylib file that replaces sqlite3.dll/so/dylib.

3. Does SQLiteStudio come with a copy of sqlcipher.dll/so/dylib? If yes, you can use it. If no, meaning SQLiteStudio linked SQLcipher statically, then you need to find a copy of sqlcipher.dll/so/dylib for your Pascal program to use. Being a crypto library, it is better to build it yourself.

PierceNg

  • Sr. Member
  • ****
  • Posts: 369
    • SamadhiWeb
Re: Example of using encrypted sqlite databases for Lazarus needed.
« Reply #2 on: October 14, 2021, 03:42:20 pm »
Being a crypto library, it is better to build it yourself.

AMHO:
a) when using an open-source database server (like SQLite)...
b) ...most of the time the publisher doesn't want to write a cryptographic layer, since it is open-source :) .

So, as said before, it's better - you should - to write your own "proprietary code" (that will produce XORed data to be stored).

I wasn't clear. I didn't mean for OP to implement the crypto they need. I just meant they should build the sqlcipher library from source, instead of downloading a binary from dunno where.

Where crypto is concerned, open is good. A good crypto system's security relies entirely on the randomness and length of key. No secret algorithms. There are enough good quality crypto libraries available.

wekwejt.com

  • New Member
  • *
  • Posts: 10
Re: Example of using encrypted sqlite databases for Lazarus needed.
« Reply #3 on: October 14, 2021, 08:14:22 pm »
Thank you PierceNg for clues!

I do it for windows systems.
So I'm going to try to build binaries.

wekwejt.com

  • New Member
  • *
  • Posts: 10
Re: Example of using encrypted sqlite databases for Lazarus needed.
« Reply #4 on: October 15, 2021, 08:48:24 pm »
Now I have made libraries an database. It works with command line but I still can't connect with Lazarus components (SQLdb or Zeos).
Some more clues?

PierceNg

  • Sr. Member
  • ****
  • Posts: 369
    • SamadhiWeb
Re: Example of using encrypted sqlite databases for Lazarus needed.
« Reply #5 on: October 16, 2021, 03:22:02 am »
Now I have made libraries an database. It works with command line but I still can't connect with Lazarus components (SQLdb or Zeos).
Some more clues?

By SQLdb I assume you mean fcl-db, and the unit usage in this chain: <your program> uses sqlite3conn, which uses sqlite3dyn, which includes sqlite3.inc. The source file sqlite3.inc defines the const Sqlite3Lib = 'sqlite3.dll'.

1. Expedient approach - Since sqlcipher.dll is just sqlite3.dll plus crypto, rename sqlcipher.dll to sqlite3.dll, placing it in the same directory as your executable. Then your program will link with it dynamically and get the crypto functionality.

2. More effort for long term payoff - Modify fcl-db source code to distinguish between loading sqlite3.dll and sqlcipher.dll.

Same way for Zeos.

Soner

  • Sr. Member
  • ****
  • Posts: 305
Re: Example of using encrypted sqlite databases for Lazarus needed.
« Reply #6 on: October 16, 2021, 09:24:10 am »
There is an example with explanations in the Lazarus folder :
lazarus-folder\examples\database\sqlite_encryption_pragma

wekwejt.com

  • New Member
  • *
  • Posts: 10
Re: Example of using encrypted sqlite databases for Lazarus needed.
« Reply #7 on: October 18, 2021, 05:41:36 pm »
Thanks guys! This is what I was looking for. :D

badmintonfan

  • New Member
  • *
  • Posts: 46
Re: Example of using encrypted sqlite databases for Lazarus needed.
« Reply #8 on: November 23, 2022, 05:36:03 am »
There is an example with explanations in the Lazarus folder :
lazarus-folder\examples\database\sqlite_encryption_pragma
I readed readme.txt under the folder carefully,and download SQLite.Interop.dll from it's official website,but I can open the the DB with any password even blank password after I create it with the dll.
fortunate I found another way finally, first download the package SQLitePCLRaw.lib.e_sqlcipher  from nuget, then unpack it and go to \runtimes\win-x64\native,place e_sqlcipher.dll in to the sample directory and rename it to sqlite3.dll.Now,the sample program works fine with this dll.

 

TinyPortal © 2005-2018