Created
October 27, 2016 04:21
-
-
Save zodani/9889576d5927a2aad15bae04c30d8cca to your computer and use it in GitHub Desktop.
decrypt a encrypted database file by sqlcipher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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