I'm trying to attach a existing sqlcipher database(encrypted) in my android application but after copying it in my directory it cannot be opened using "SQLiteDatabase.openDatabase(...)"
I tried the code in normal sqlite and it works correctly but when I used sqlcipher API i got this error message
//CREATE TABLE android_metadata failed
//Failed to setLocale() when constructing, closing the database
// net.sqlcipher.database.SQLiteException: file is encrypted or is not a database
I used the following code inside SQLiteOpenHelper Class :
if(!dbExist1)
{
this.getWritableDatabase(password);
this.openDatabase();
try
{
this.close();
copyDataBase();
}
catch (IOException e)
{
throw new Error("Error copying database");
}
}
public SQLiteDatabase openDatabase() throws SQLException {
String DBPath = DATABASE_PATH + DATABASE_NAME;
myDataBase = SQLiteDatabase.openDatabase(DBPath, password, null,
SQLiteDatabase.NO_LOCALIZED_COLLATORS);
return myDataBase;
}
And I used the following code inside Activity Class :
SQLiteDatabase.loadLibs(this);
DataBaseHelper myDbHelper ;
myDbHelper = new DataBaseHelper(this);
SQLiteDatabase db=myDbHelper.openDatabase();
i tried to use this solution but still same error
Blockquote
Thanks a lot Nick Parker ,actually i used a code snippet from your sample and i created a new class representing SqlCipherAssestHelper that copy the encrypted DataBase from assets to another location in the device and read/write from the new copy using the database in the sample "1x.db" here
this is the Helper Calss:
and this code inside activity :
Are you certain you provided the correct passphrase to the database? Does your database have a configuration (i.e., cipher, page size, kdf iteration length, etc) that differ from the default SQLCipher distribution? I have an example of attaching another SQLCipher database here within the test suite, you might consider running the test suite locally to compare. You might also consider posting this question with your additional details on the SQLCipher mailing list.