Reputation: 2834
I've created an encrypted database using C#-SQLite after reading that it was compatible with SQLCipher. I'm using the following command to encrypt:
PRAGMA hexkey="0x0102030405060708090A0B0C0D0E0F01";
I'm attempting to open the file using SQLCipher by creating a char array of the key and converting to String to use as the password as follows:
private static final char[] DB_KEY = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x01 };
String password = new String(DB_KEY);
mDatabase = SQLiteDatabase.openOrCreateDatabase(dbPath, password, null);
This throws an exception that the database is not a database or encrypted.
Firstly, I would like to confirm that the encryption is even compatible with SQLCipher as this is information I got from a StackOverflow question and if I'm barking up the wrong tree I'll move on.
If it is compatible, what am I doing wrong with the decryption?
Upvotes: 0
Views: 1661
Reputation: 1388
The format you are using is not correct for a raw hex key. To use a raw hex key within SQLCipher you must format your string such that it is prefixed with an x followed by a single quote, then a 64 character hex string and terminated with a single quote. A PRAGMA
statement might look something like this:
PRAGMA key = "x'2DD29CA851E7B56E4697B0E1F08507293D761A05CE4D1B628663F411A8086D99'";
In the event of using SQLCipher for Android, your String might look something like this:
String key = "x\'2DD29CA851E7B56E4697B0E1F08507293D761A05CE4D1B628663F411A8086D99\'";
Upvotes: 1