'How to use Command Line to access an encrypted SQLite db file instead of DB Browser interface

Currently I can use DB Browser for SQLite to open an encrypted DB file with password on Mac.

DB Browser to open DB

The options as per image:

  • Raw key (start with 0x...)
  • SQLCipher 3 defaults

I would like to open this file using command line instead of DB Browser.

Tried follow commands but seems no luck so far.

sqlcipher xxx.db
SQLite version 3.37.2 2022-01-06 13:25:41 (SQLCipher 4.5.1 community)
Enter ".help" for usage hints.
sqlite> pragma key="0xMyKey";
ok
sqlite> .tables
Error: file is not a database

Appreciate the help in advance so that I can use command line to access or export sqlite db just like mysql (mysql -u ... & mysqldump).



Solution 1:[1]

Found the documentation via this link: https://www.zetetic.net/sqlcipher/sqlcipher-api/

sqlcipher xxx.db
SQLite version 3.37.2 2022-01-06 13:25:41 (SQLCipher 4.5.1 community)
Enter ".help" for usage hints.
sqlite> PRAGMA key = "x'{KEY_WITHOUT_0X}'"; // Replace {KEY_WITHOUT_0X} with your key without 0x!
ok
sqlite> PRAGMA cipher_page_size = 1024;
sqlite> PRAGMA kdf_iter = 64000;
sqlite> PRAGMA cipher_hmac_algorithm = HMAC_SHA1;
sqlite> PRAGMA cipher_kdf_algorithm = PBKDF2_HMAC_SHA1;
sqlite> PRAGMA cipher_default_plaintext_header_size = 0;
sqlite> 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Joe