SQLite with encryption/password protection

后端 未结 9 1088
遇见更好的自我
遇见更好的自我 2020-11-22 07:45

I\'m just learning to use SQLite and I was curious if such is possible:

  1. Encryption of the database file?

  2. Password protect opening of the dat

相关标签:
9条回答
  • 2020-11-22 08:02

    You can always encrypt data on the client side. Please note that not all of the data have to be encrypted because it has a performance issue.

    0 讨论(0)
  • 2020-11-22 08:03

    SQLite has hooks built-in for encryption which are not used in the normal distribution, but here are a few implementations I know of:

    • SEE - The official implementation.
    • wxSQLite - A wxWidgets style C++ wrapper that also implements SQLite's encryption.
    • SQLCipher - Uses openSSL's libcrypto to implement.
    • SQLiteCrypt - Custom implementation, modified API.
    • botansqlite3 - botansqlite3 is an encryption codec for SQLite3 that can use any algorithms in Botan for encryption.
    • sqleet - another encryption implementation, using ChaCha20/Poly1305 primitives. Note that wxSQLite mentioned above can use this as a crypto provider.

    The SEE and SQLiteCrypt require the purchase of a license.

    Disclosure: I created botansqlite3.

    0 讨论(0)
  • 2020-11-22 08:06

    The .net library System.Data.SQLite also provides for encryption.

    0 讨论(0)
  • 2020-11-22 08:07

    I had also similar problem. Needed to store sensitive data in simple database (SQLite was the perfect choice except security). Finally I have placed database file on TrueCrypt encrypted valume.

    Additional console app mounts temporary drive using TrueCrypt CLI and then starts the database application. Waits until the database application exits and then dismounts the drive again.

    Maybe not suitable solution in all scenarios but for me working well ...

    0 讨论(0)
  • 2020-11-22 08:09

    You can use SQLite's function creation routines (PHP manual):

    $db_obj->sqliteCreateFunction('Encrypt', 'MyEncryptFunction', 2);
    $db_obj->sqliteCreateFunction('Decrypt', 'MyDecryptFunction', 2);

    When inserting data, you can use the encryption function directly and INSERT the encrypted data or you can use the custom function and pass unencrypted data:

    $insert_obj = $db_obj->prepare('INSERT INTO table (Clear, Encrypted) ' .
     'VALUES (:clear, Encrypt(:data, "' . $passwordhash_str . '"))');

    When retrieving data, you can also use SQL search functionality:

    $select_obj = $db_obj->prepare('SELECT Clear, ' .
     'Decrypt(Encrypted, "' . $passwordhash_str . '") AS PlainText FROM table ' .
     'WHERE PlainText LIKE :searchterm');
    0 讨论(0)
  • 2020-11-22 08:12

    You can get sqlite3.dll file with encryption support from http://system.data.sqlite.org/.

    1 - Go to http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki and download one of the packages. .NET version is irrelevant here.

    2 - Extract SQLite.Interop.dll from package and rename it to sqlite3.dll. This DLL supports encryption via plaintext passwords or encryption keys.

    The mentioned file is native and does NOT require .NET framework. It might need Visual C++ Runtime depending on the package you have downloaded.

    UPDATE

    This is the package that I've downloaded for 32-bit development: http://system.data.sqlite.org/blobs/1.0.94.0/sqlite-netFx40-static-binary-Win32-2010-1.0.94.0.zip

    0 讨论(0)
提交回复
热议问题