5

I have a encrypted sqlite db and its key. (Which is generated by an android program). However, when I open the db in command line I can not read the db. The command line tool is installed by:

brew install sqlcipher

I open the database by:

sqlcipher EnDB.db
>pragma key="6b74fcd";
>select * from bizinfo;

It keeps telling me "Error: file is encrypted or is not a database"

However, if I open the database file with gui app sqlite database browser (which is a windows program and I run it in wine). It pops up a window for me to enter the key, with 6b74fcd as the key it successfully read the database.

sqlite database browser

As I want to automatically process the db in the future, I can not depend on the GUI. Do you know why the command line is not working?

Min Lin
  • 3,177
  • 2
  • 19
  • 32
  • can you tell us where you got this version of sqlite browser from? Because the version at http://sqlitebrowser.org/ does not support encrypted databases. – Vinay W Aug 04 '14 at 06:48
  • @VinayWadhwa http://valentin.dasdeck.com/xtras/sqlite_xtra/win/tools/ – Min Lin Aug 04 '14 at 10:49
  • Thanks, also - you might want to try to decrypt the database permanently - http://stackoverflow.com/questions/25132477/how-to-decrypt-an-encrypted-sqlcipher-database-file-on-command-line/25132478#25132478 – Vinay W Aug 05 '14 at 06:38
  • how did you encrypted the db using sqlcipher? is there any tutorial? if possible please take a look at this: https://stackoverflow.com/questions/62229318/how-to-encrypt-a-sqlite-database-using-sqlcipher – Taba Jun 06 '20 at 18:14

2 Answers2

6

Solved already!

after

pragma key="6b74fcd";

Call this:

pragma cipher_use_hmac=off;

Then everything works like a charm. It seems the database is a 1.x database.

Min Lin
  • 3,177
  • 2
  • 19
  • 32
0

Since I had to go through some trouble with a similar issue, here's what helped in my case.

After opening the database in the Terminal via

sqlcipher mydatabase.db

I made sure the compatibility was given

PRAGMA cipher_default_compatibility = 1;

Then I provided the key

PRAGMA key='theKey';

Now, I could use SQL statements like

SELECT * FROM myTable;

Obviously, make sure that things like "mydatabase.db", "theKey" and "myTable" are replaced with your individual database name, key and table name.

uem
  • 713
  • 1
  • 7
  • 18