Recently, due to project needs, the sqlite generated on the server side needs to be encrypted. The server backend is written in PHP, and the operating system is CentOS. The open source sqlite3 has reserved a database encryption interface, but it has not been implemented. So on the Internet Found SQLCipher, which implements the encryption function not implemented by sqlite3, and can support sqlite database encryption by recompiling PHP's sqlite3 extension.
For specific operations, please refer to the steps on the official website, address: https: //www.zetetic.net/sqlcipher/sqlcipher-for-php/
For the operation of the official website, the system is using Ubuntu. Here you can convert the corresponding commands to those used under CentOS. Refer to the official website After the operation steps, the compilation can be successful.
After the compilation is successful, sqlite3.so will be generated. Just replace the sqlite3.so in the previous server php extension (it is best to make a backup before replacing). The replacement is completed After that, restart the apache server,
come down to test, test code:
//Create a test.sqlite file, the password is 12345678, parameters 6 means open it if it exists, create it if it doesn’t. For specific information, please refer to sqlite3.c in the source file for relevant viewing
$db=new Sqlite3("test.sqlite",6,"12345678");
$db->exec("create table mytest (name varchar(200) )");
$db->exec("insert
into mytest (name) values ('aaaa')");
$result
= $db->query('SELECT * FROM mytest');
print_f($result);
?>
If you can print out the result, it means that sqlite3 has been recompiled successfully. This is basically a success, but you still need to check whether the generated database has been encrypted. You can use the generated test.sqlite with some of your own Try opening the tool and it will usually prompt an error. At this time, it means that SQLite has been successfully encrypted.
By the way, there are also steps to support Android and IOS on the official website, which can be viewed on the official website.
Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.
The above introduces how php under CentOS compiles sqlite3 through SQLCipher to support database encryption, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.