Skip to content

Instantly share code, notes, and snippets.

@zodani
Created December 20, 2016 00:40
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/274622cdce9d0fc85edf2e620e2315ed to your computer and use it in GitHub Desktop.
Save zodani/274622cdce9d0fc85edf2e620e2315ed to your computer and use it in GitHub Desktop.
SQLCipher decrypt
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;");
SQLiteDatabase sqlDB = SQLiteDatabase.openOrCreateDatabase(unencFile, null);
sqlDB.close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment