Encrypt and decrypt .sqlite file problem in cocos2dx in c++

I have a game in ios and android. I used cocos2dx2.2.2 version. I have a database.sqlite file in my resource folder and my game uses a lot of logic from my database table. I just want to encrypt the .sqlite and then in my c++ code i should decrypt that file for use.
I want to do encryption so that my database doesn’t gets leaked when the game becomes live.
So, is there anyway to do that in cocos2d-x. Any tutorial or sample. I am unable to find any links regarding cocos2dx
Thanks in Advance. Any help will be highly appreciated

1 Like

I guess you could use OpenSSL to do this. decrypt on game start and re-encrypt as you require.

I wouldn’t use OpenSSL for this, you need to build it into the SQLite engine or it won’t be safe with transactions.

Your goal feature set is very similar to SQLite Encryption Extension (SEE) for SQLite. If you cannot pay for it yourself, it is possible to implement your own.

I use an AES encryption implementation of SQLite for my SQlite databases in 2.2.x

I also build an sqlite3 command line that supports .key and a lib that can be dropped into other tools for GUI and stuff.

All very doable, just takes some work.

Don’t want to do the work, you can also buy SQLite Encryption Extension (SEE) for SQLite from the SQLite team.

@corytrese Thanks for replying. SEE looks interesting!

I did see this: https://github.com/shenghe/FreeSQLiteEncryption Now sure if it is possible to adapt to your needs.

That is almost exactly the same as my solution.

The critical implementation being these two methods

  int sqlite3_key( sqlite3 *db, const void *pKey, int nKey) 
  int sqlite3_rekey( sqlite3 *db, const void *pKey, int nKey)

Then before you use any SQL commands, you issue something like this

.key MY_PRIVATE_KEY

SEE - The official implementation.
wxSQLite - A wxWidgets style c++ wrapper that also implements SQLite’s encryption.
SQLCipher - Uses openSSL’s libcrypto to implement.
SQLiteCrypt - Custom implementation, modified API.