Sqlite encryption in php

Hello, I’m very impressed with ExeOutput :smile:
I’m prepairing small project which include also Sqlite db. with some sensitive information so I try to password protect it.

I have try following code $db = new SQLite3($dbname, 066, $encryption_key); the db was created but it wasn’t passoword protected.

After a day spent searching for solution I don’t find a solution for Sqlite encryption or password protection with php and ExeOutput. Is this possible?

I know that oficial encryption cost about 2000 usd but is there a way around to use some built in php function?


You could crypt values yourself with PHP code before storing them into your SQLite database. PHP has a lot of encryption functions.

Yes thats correct but in this case is very hard to perform search, update and use records in db, because you have to decrypt whole db.

I was thinking about using sqlite3.dll that allow encryption. For example: http://sqlite-crypt.com/download.htm or. https://github.com/rindeal/SQLite3-Encryption

Is it possible to use this sqlite.dll in Exeoutput so the encryption can be used?
Is there an example how to use such dll in php and Exeoutput?


Not tested, but maybe this can help:

I’ve also found this: https://www.zetetic.net/sqlcipher/sqlcipher-for-php/
But this requires rebuilding the entire PHP runtime. We’ll see.


Phpclass is OK, but it works with decrypted db, and encrypt it on the end and save it. I will test it with our app and see the output. The problem is that when using the db, it is visablble to other programs. Is it possible to decrypt it only in memory of Exeoutput?

What about the .dll https://github.com/rindeal/SQLite3-Encryption Is it possible to include it into Exeoutput.


Sure, you can compile your existing SQLite database into ExeOutput and it will be stored as a virtual file, only accessible by your program. However, changes won’t be saved unless you encrypt your database into an external file before the application closes.

Know this is old, very old but…

Has anyone discovered a way to lock or provide any type of encryption to sqlite? I cannot compile into exe and need to have in outside data folder.

Not looking for hacker proof, just looking to keep casual user from changing db tables.

See open source version of https://www.zetetic.net/sqlcipher/open-source/ which http://sqlitebrowser.org/ has incorporated. But see know way can use with EXEOut.

In a future release, we’ll add the ability to decrypt/encrypt external files, a similar feature already exists in HTMLEXE.

1 Like

I was in need of this myself and managed to build a php_pdo_sqlcipher extension (dll) that works like pdo_sqlite with all the encrypt / decrypt methods baked in from the sqlcipher project. I’ve put the built DLL on GitHub although it’s likely not hacker proof and currently only for PHP 5.6. If there’s enough interest I’ll add the steps it took to build.


Hello Mfink,

I am interested.


Thanks @mfink, much appreciated. I would love to know how you made it.

Will try this on some older PHP 5.6 projects. Pretty much moved all new projects to PHP 7 : (

Thanks again for sharing.

Hot off the presses, I’ve added the steps to build for Windows here: https://github.com/kynetiv/php_pdo_sqlcipher/blob/master/examples/BUILD.md

Also built it with PHP 7 and added the built DLL. Let mew know how it works out for you or if you have any questions :slight_smile:


That is a very in-depth tutorial. Can tell that took some time.

Going to give a shot after the Holiday company goes home in a few days. Thank you once again for sharing.

1 Like

@mfink I had forgotten to thank you again for this!

We gave it a run in school computer lab and failed a few times (our mistype) but in end had working version. When get time, going to have to try for PHP7.2

Thanks again for the in-depth tutorial on GitHub.

1 Like

Still interested in the feature:)

1 Like

Just saw this. So glad it helped! It certainly is a walk in the dark to get this going.

For others who’ve commented on Github, I realized I should have mentioned you’ll need to include the php_curl dll to be compiled in the module since there isn’t a way (that I know of anyway!) to include the required OpenSSL dlls (ssleay32.dll & libeay32.dll) in the compiliation without curl (which does this by default).


1 Like

I did a small project with SQLite3 and pdo_sqlciper. I works fine just current public version only work with php 7.1.

Hello. How do you get pdo_sqlciper? This library works with phpdesktop? Thanks.

Is this feature released ?

The feature to encrypt external file (like in a data folder) has been implemented. You can choose to have external file, choose encryption and keep file in a folder. Have not used it, so can’t really comment about usage.