Sqlite3 encryption Scheme Sqlcipher, and Sqlcipher User Guide

Source: Internet
Author: User
Tags openssl sqlite sqlite database

SQLite is an open-source lightweight database that is now used by both Android and iOS to store structured data, but the encrypted version is not open source. Compromise only open source solution, Sqlcipher is a good choice, it can be encrypted with sqlite, and there are corresponding libraries in both Android and iOS to decrypt the read, but the introduction of the library will increase the size of the app. SQLCipher is a open source library that provides transparent, secure 256-bit AES encryption of SQLite database files.
1. Download the source code
Official Source code: Https://github.com/sqlcipher/sqlcipher
2. Related dependencies
Installing OpenSSL and Tcl, these two dependencies must be installed, or it would be tragic
OpenSSL installs with Yum Openssl-devel, Tcl installs with Yum Tcl-devel
3. Compiling
./configure–enable-tempstore=yes cflags= "-dsqlite_has_codec" ldflags= "-lcrypto"
Make
4. Verify that the compilation is successful
Create an encrypted data, the password is AAA:

$ sqlcipher test.sqlite
sqlite version 3.7.14.1 2012-10-04 19:37:12
enter ". Help" for INSTRUCTIONS
enter SQL statements terminated with a"; "
sqlite> PRAGMA key = ' AAA ';
sqlite> CREATE TABLE A (ind int);
sqlite>. TABLES
a
sqlite>. QUIT
try not to enter a password, directly read the database, in theory, cannot read the data, or error:

$ sqlcipher test.sqlite
sqlite version 3.7.14.1 2012-10-04 19:37:12
enter ". Help" for INSTRUCTIONS
enter SQL statements terminated with a"; "
sqlite>. TABLES
sqlite> quit
Try to enter the password correctly, it should be read successfully:

$ sqlcipher test.sqlite
sqlite version 3.7.14.1 2012-10-04 19:37:12
enter ". Help" for INSTRUCTIONS
enter SQL statements terminated with a"; "
sqlite> PRAGMA key = ' AAA ';
sqlite>. TABLES
a
sqlite>. Quit

Encrypt existing data
How to encrypt an existing SQLite file, there is no other easy way:

1. Export the data first:

$ sqlite3 Ifood.sqlite
>.output Ifood.sql
>.dump
2. Create a new encrypted database:

$ sqlcipher Ifood_lock.sqlite
sqlite> PRAGMA key = ' abcdef '; # Set Password
3. Import data

>.read Ifood.sql

SQLCipher for Android
Https://github.com/sqlcipher/sqlcipher
This is the source code need to compile, more trouble, can go to http://download.csdn.net/detail/wdxin1322/8378519

The use is very simple, you can refer to the Https://www.zetetic.net/sqlcipher/sqlcipher-for-android/, and then change the import of Sqllite in the project to the corresponding sqlcipher.

My personal blog Program Ape Diary--Wang new personal blog

Sqlite3 encryption Scheme Sqlcipher, and Sqlcipher User Guide

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.