Implementing SQL AES ENCRYPTION into SQLite using PHP

喜夏-厌秋 提交于 2019-12-31 04:02:49

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/12712667/implementing-sql-aes-encryption-into-sqlite-using-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!