Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

encryption - How to decrypt an encrypted sqlcipher database file on command line?

The question is simple

What I have is:

  • I have a database file which is encrypted using sqlcipher.
  • I also have the passphrase which was used to encrypt this db file

What I need is:

  • I need to decrypt the database file/ need a database file which is unencrypted/non encrypted/decrypted.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Download and Build sqlcipher

--Skip this if sqlcipher is already installed

Pull the code from https://github.com/sqlcipher/sqlcipher in a directory (say ~/sqlcipher)
mkdir ~/bld;        #  Build will occur in a sibling directory
cd ~/bld;           #  Change to the build directory
../sqlcipher/configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="-lcrypto"; 
                    #configure sqlcipher 

make install;       #  Install the build products

Decrypt the database to a plaintext database

$ cd ~/;
$ ./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; 

Find the decrypted database at ~/plaintext.db which you can use with any sqlite browser like this.

Update : September 2015

http://sqlitebrowser.org now supports sqlcipher databases. That's neat.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...