Hi Thanks for the quick response, I am following the ImportUnencryptedDatabaseTest very closely, I do have a plain text db file that is supplied into this function and that opens fine, but the above mentioned line for the encryptedDB fails with the issue “Net.sqlcipher.database.SQLiteException: file is encrypted or is not a database”.
Do I need to create this DB before by trying db= SQLiteDatabase.openOrCreateDatabase(encryptedDatabase, passphrase, null); or somethign to make it work, I have tried the example and it works fine in that.
If I change the routine to use a temp file then it seems to not coomplain on this line any more, but a different issue comes up later on. It doesn’t migrate the tables from the plain DB to the encrypted one, and on opening the encrypted db later complains of missing tables, that are surely supposed to be in it
public static void encrypt(Context ctxt, File unencryptedDatabase,
String passphrase) {
if (unencryptedDatabase.exists()) {
No, creating the file before hand that you wish to export to is not required, SQLCipher will create it if necessary. Can you try running your scenario through the SQLCipher command line shell? What is the value of this part of your app?
String.format("ATTACH DATABASE '%s' AS encrypted KEY '%s'", newFile.getAbsolutePath(), passphrase);
Hi,
I have just fixed it, the problem was when I used the non-temp file solution. The line of code
db.rawExecSQL(String.format(“ATTACH DATABASE ‘%s’ AS encrypted KEY ‘%s’”, path, passphrase));
would raise an exception if the ‘path’ already exists. Many Thanks for your help