SQLite with encryption/password protection

后端 未结 9 1075
遇见更好的自我
遇见更好的自我 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: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');

提交回复
热议问题