Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.
like image 204
Vinay W Avatar asked Aug 05 '14 06:08

Vinay W


People also ask

How do I decrypt an encrypted database?

You can return an encrypted database to an unencrypted state by specifying attributes on the connection URL. To decrypt an encrypted database, specify the decryptDatabase=true attribute in conjunction with either the bootPassword=key attribute or the encryptionKey=key attribute.

How do I decrypt a db file?

Decrypt the database to a plaintext database 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.

How do I open an encrypted SQLite file?

Right-click on your db file in its folder and select "open with..." then select the exe for SQLite2009 Pro, or drag the file onto the exe (assuming you're on Windows), or pass the file path to the exe via the cmd line.

What encryption does SQLCipher use?

SQLCipher does not implement its own encryption. Instead it uses the widely available encryption libraries like OpenSSL libcrypto, LibTomCrypt, and CommonCrypto for all cryptographic functions.

How to decrypt database in SQL Server?

Decrypt SQL Server database just needs to reset user password for opening database file. So select SA account and click Reset button under user list. A new window pops up. Type new password for this user account and click OK.

How do I open an encrypted SQLCipher database in SQLite?

Another option: you can use the command line tool with sqlcipher_export () to export an encrypted database to a standard sqlite database, which you can then open with any tool. Note that this will expose all of the confidential information in the SQLCipher database, so it's only appropriate for test data.

How to decrypt a database in dbdefence?

To decrypt a currently attached database, you need to start Encryptor, select the database and provide the encryption password. Decryption is as fast as encryption. Since version 9 DbDefence can decrypt a database from SQL query. Just add parametrer '-X' to dbd_encrypt_db. Parameter -X means decryption. No need to specify other encryption options.

How do I remove encryption from a SQL Server database?

If the database is encrypted, you must first remove encryption from the database by using the ALTER DATABASE statement. Wait for decryption to complete before removing the database encryption key. For more information about the ALTER DATABASE statement, see ALTER DATABASE SET Options (Transact-SQL).


1 Answers

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.

like image 94
Vinay W Avatar answered Sep 19 '22 12:09

Vinay W