» 2015 » July の記事

~ encrypt and Decrypt the sqlite ~

connie 2015.07.15 | android | | No Comments

encrypt the DB

sqlcipher plaintext.db
sqlite> ATTACH DATABASE 'encrypted.db' AS encrypted KEY 'testkey';
sqlite> SELECT sqlcipher_export('encrypted');
sqlite> DETACH DATABASE encrypted;

========
TEST DB

hexdump -C plaintext.db
hexdump -C encrypted.db

decrypt the DB

$ ./sqlcipher encrypted.db
sqlite> PRAGMA key = 'testkey';
sqlite> ATTACH DATABASE 'plaintext.db' AS plaintext KEY '';  — empty key will disable encryption
sqlite> SELECT sqlcipher_export('plaintext');
sqlite> DETACH DATABASE plaintext;

~ Install sqlcipher in osx ~

connie 2015.07.13 | Uncategorized | | No Comments
# clone the repo
git clone https://github.com/sqlcipher/sqlcipher.git
pushd sqlcipher

# check if there are any interesting options
./configure --help

# CFLAGS will turn on encryption, default temp_store to memory,
# (file usage optional), enable full-text search, link to libcrypto
./configure CFLAGS="-DSQLITE_HAS_CODEC -DSQLITE_TEMP_STORE=2 -DSQLITE_ENABLE_FTS3 -lcrypto"

# just to be sure everything is in the initial state
make clean

# use as many CPUs as exist
# (you could also use 'sysctl -n hw.physicalcpu', which would not include 'logical' cores)
time make -j $(sysctl -n hw.ncpu)

 

sudo make install

which sqlcipher
| HOME |

Smiley face

July 2015
S M T W T F S
 1234
567891011
12131415161718
19202122232425
262728293031