The encrypted db can be read/written in C program using sqlite3_key(). However command line use failed:
.\sqlcipher\sqlite3.exe data.db
SQLite version 3.36.0 2021-06-18 18:36:39 (SQLCipher 4.5.0 community)
Enter “.help” for usage hints.
sqlite> PRAGMA key = “x’xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx’”;
sqlite> .schema
Error: file is not a database
The sqlite3.exe is built from community repo of sqlcipher together with the sqlite3.lib being used in C.
Thank you for you interest in SQLCipher and for posting to the discussion forum.
A few preliminary suggestions/questions:
Try opening the database using DB Browser for SQLite: https://sqlitebrowser.org (there’s a raw key dropdown when you’re presented with the SQLCipher encryption prompt):
I downloaded the Windows version and run ‘DB Browser for SQLCipher.exe’, click ‘Open Database’, enter the raw key (with anything else intact) then click OK, the same dialog pops out again. If I close it, it says ‘Could not open database file. Reason: invalid format’.
Regarding the curly double quotes, I did use ASCII quote in command line.
If you’d like to use a raw key (without key derivation) using sqlite3_key you’ll want to pass in a hex string in SQLITE BLOB format and then specify the length of the entire key. Here’s an example:
OK but I think it is different from sqlite3’s docs.
int sqlite3_key_v2(
sqlite3 *db, /* The connection from sqlite3_open() */
const char *zDbName, /* Which ATTACHed database to key */
const void *pKey, /* The key */
int nKey /* Number of bytes in the key */
);
I think if you want to mandate this format, it shouldn’t return 0 given a binary array.
Thanks for reminding me anyway. I can now use like
PRAGMA hexkey='796f75722d7365637265742d6b6579';
to read the db.