how to decrypt sqlite database android using sqlcipher?

1.7k views Asked by At

I need a local database for my application.I created one and i encrypted it.(I know the pw).Now i want to load this db to my original application's assets folder.I want to decrypt it before copy. I had a copy code like this this is working for unencrpyted db. How can I translate this for my encrypted db.Thanks

private void copyDataBase() throws IOException {

    //Open your local db as the input stream
    InputStream myInput = myContext.getAssets().open(DB_NAME);

    // Path to the just created empty db
    String outFileName = DB_PATH + DB_NAME;

    //Open the empty db as the output stream
    OutputStream myOutput = new FileOutputStream(outFileName);

    //transfer bytes from the inputfile to the outputfile
    byte[] buffer = new byte[5120];
    int length;
    while ((length = myInput.read(buffer)) > 0) {
        myOutput.write(buffer, 0, length);
    }

    //Close the streams
    myOutput.flush();
    myOutput.close();
    myInput.close();

}
1

There are 1 answers

1
Stephen Lombardo On

The proper way to do this would be to copy the encrypted database into a local folder. Then you can open it with SQLCipher and use sqlcipher_export() to convert it into a standard (non-encrypted) SQLite database.