Skip to content

Instantly share code, notes, and snippets.

@zodani
Created October 27, 2016 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zodani/9889576d5927a2aad15bae04c30d8cca to your computer and use it in GitHub Desktop.
Save zodani/9889576d5927a2aad15bae04c30d8cca to your computer and use it in GitHub Desktop.
decrypt a encrypted database file by sqlcipher
public void decrypt() {
if(db.isOpen()) {
File unencFile = mContext.getDatabasePath("decrypted.db");
if(!unencFile.exists()) {
db.rawExecSQL(String.format("ATTACH DATABASE '%s' as plaintext KEY '';", unencFile.getAbsolutePath()));
db.rawExecSQL("SELECT sqlcipher_export('plaintext');");
db.rawExecSQL("DETACH DATABASE plaintext;");
android.database.sqlite.SQLiteDatabase sqlDB = android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(unencFile, null);
sqlDB.close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment