Implementing SQL AES ENCRYPTION into SQLite using

2020-04-18 06:43发布

is it possible to implement SQL AES_ENCRYPT/AES_DECRYPT into SQLite using PHP ? For example I have a PHP Code:

$SQL = "INSERT INTO parent (Request, Column1, Column2) VALUES ('$Request',AES_ENCRYPT('$Col1','$key'),AES_ENCRYPT('$Col2','$key'))";

and this query works in SQL, but is it possible to use this same query in SQLite?

标签: php sql sqlite aes
2条回答
Rolldiameter
2楼-- · 2020-04-18 07:08

I'd say you have 2 options :

  • encrypt your values at the PHP level and store them as BLOBs or base64 strings

  • encrypt the whole database executing the following command (just like any other regular SQL command) : PRAGMA hexkey='0x_your_key_in_hex_format' . Don't forget do do the same when you open your database for running SELECT queries. Here is the official documentation.

查看更多
看我几分像从前
3楼-- · 2020-04-18 07:09

Well, about 10 minutes ago I finished installing PHP 7.2.2 on my HP laptop with Ubuntu 16.04 LTS 64bit. You do not need to acquire a license for SQLite Encryption Extension (SEE). On top of existing PHP extension I have added a few C files with AES and SQLite functions for en/decrypting Pager. It works well and now I will try to make it work using Intel i5 built-in AES functionality - to get the best out of hardware itself. Now, to open a sqlite db I can use the following:

class MyDB extends SQLite3 {
      function __construct(){
        $this->open('sqlite3.db',SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE, 'your_password_here');
      }
}

Encrypting the whole database is definitely the best solution. Write me a message for details. I will probably publish this solution soon.

查看更多
登录 后发表回答