Java Code Examples for net.sqlcipher.database.SQLiteStatement#execute()
The following examples show how to use
net.sqlcipher.database.SQLiteStatement#execute() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SQLCipherUtils.java From cwac-saferoom with Apache License 2.0 | 5 votes |
/** * Replaces this database with a version encrypted with the supplied * passphrase, deleting the original. Do not call this while the database * is open, which includes during any Room migrations. * * The passphrase is untouched in this call. If you are going to turn around * and use it with SafeHelperFactory.fromUser(), fromUser() will clear the * passphrase. If not, please set all bytes of the passphrase to 0 or something * to clear out the passphrase. * * @param ctxt a Context * @param originalFile a File pointing to the database * @param passphrase the passphrase from the user * @throws IOException */ public static void encrypt(Context ctxt, File originalFile, byte[] passphrase) throws IOException { SQLiteDatabase.loadLibs(ctxt); if (originalFile.exists()) { File newFile=File.createTempFile("sqlcipherutils", "tmp", ctxt.getCacheDir()); SQLiteDatabase db= SQLiteDatabase.openDatabase(originalFile.getAbsolutePath(), "", null, SQLiteDatabase.OPEN_READWRITE); int version=db.getVersion(); db.close(); db=SQLiteDatabase.openDatabase(newFile.getAbsolutePath(), passphrase, null, SQLiteDatabase.OPEN_READWRITE, null, null); final SQLiteStatement st=db.compileStatement("ATTACH DATABASE ? AS plaintext KEY ''"); st.bindString(1, originalFile.getAbsolutePath()); st.execute(); db.rawExecSQL("SELECT sqlcipher_export('main', 'plaintext')"); db.rawExecSQL("DETACH DATABASE plaintext"); db.setVersion(version); st.close(); db.close(); originalFile.delete(); newFile.renameTo(originalFile); } else { throw new FileNotFoundException(originalFile.getAbsolutePath()+" not found"); } }
Example 2
Source File: SQLCipherUtils.java From cwac-saferoom with Apache License 2.0 | 5 votes |
/** * Replaces this database with a decrypted version, deleting the original * encrypted database. Do not call this while the database is open, which * includes during any Room migrations. * * The passphrase is untouched in this call. Please set all bytes of the * passphrase to 0 or something to clear out the passphrase if you are done * with it. * * @param ctxt a Context * @param originalFile a File pointing to the encrypted database * @param passphrase the passphrase from the user for the encrypted database * @throws IOException */ public static void decrypt(Context ctxt, File originalFile, byte[] passphrase) throws IOException { SQLiteDatabase.loadLibs(ctxt); if (originalFile.exists()) { File newFile= File.createTempFile("sqlcipherutils", "tmp", ctxt.getCacheDir()); SQLiteDatabase db= SQLiteDatabase.openDatabase(originalFile.getAbsolutePath(), passphrase, null, SQLiteDatabase.OPEN_READWRITE, null, null); final SQLiteStatement st=db.compileStatement("ATTACH DATABASE ? AS plaintext KEY ''"); st.bindString(1, newFile.getAbsolutePath()); st.execute(); db.rawExecSQL("SELECT sqlcipher_export('plaintext')"); db.rawExecSQL("DETACH DATABASE plaintext"); int version=db.getVersion(); st.close(); db.close(); db=SQLiteDatabase.openDatabase(newFile.getAbsolutePath(), "", null, SQLiteDatabase.OPEN_READWRITE); db.setVersion(version); db.close(); originalFile.delete(); newFile.renameTo(originalFile); } else { throw new FileNotFoundException(originalFile.getAbsolutePath()+" not found"); } }
Example 3
Source File: SQLCipherUtils.java From kripton with Apache License 2.0 | 5 votes |
/** * Replaces this database with a version encrypted with the supplied * passphrase, deleting the original. Do not call this while the database * is open, which includes during any Room migrations. * * The passphrase is untouched in this call. If you are going to turn around * and use it with SafeHelperFactory.fromUser(), fromUser() will clear the * passphrase. If not, please set all bytes of the passphrase to 0 or something * to clear out the passphrase. * * @param ctxt a Context * @param originalFile a File pointing to the database * @param passphrase the passphrase from the user * @throws IOException */ public static void encrypt(Context ctxt, File originalFile, byte[] passphrase) throws IOException { SQLiteDatabase.loadLibs(ctxt); if (originalFile.exists()) { File newFile=File.createTempFile("sqlcipherutils", "tmp", ctxt.getCacheDir()); SQLiteDatabase db= SQLiteDatabase.openDatabase(originalFile.getAbsolutePath(), "", null, SQLiteDatabase.OPEN_READWRITE); int version=db.getVersion(); db.close(); db=SQLiteDatabase.openDatabase(newFile.getAbsolutePath(), passphrase, null, SQLiteDatabase.OPEN_READWRITE, null, null); final SQLiteStatement st=db.compileStatement("ATTACH DATABASE ? AS plaintext KEY ''"); st.bindString(1, originalFile.getAbsolutePath()); st.execute(); db.rawExecSQL("SELECT sqlcipher_export('main', 'plaintext')"); db.rawExecSQL("DETACH DATABASE plaintext"); db.setVersion(version); st.close(); db.close(); originalFile.delete(); newFile.renameTo(originalFile); } else { throw new FileNotFoundException(originalFile.getAbsolutePath()+" not found"); } }
Example 4
Source File: SQLCipherUtils.java From kripton with Apache License 2.0 | 5 votes |
/** * Replaces this database with a decrypted version, deleting the original * encrypted database. Do not call this while the database is open, which * includes during any Room migrations. * * The passphrase is untouched in this call. Please set all bytes of the * passphrase to 0 or something to clear out the passphrase if you are done * with it. * * @param ctxt a Context * @param originalFile a File pointing to the encrypted database * @param passphrase the passphrase from the user for the encrypted database * @throws IOException */ public static void decrypt(Context ctxt, File originalFile, byte[] passphrase) throws IOException { SQLiteDatabase.loadLibs(ctxt); if (originalFile.exists()) { File newFile= File.createTempFile("sqlcipherutils", "tmp", ctxt.getCacheDir()); SQLiteDatabase db= SQLiteDatabase.openDatabase(originalFile.getAbsolutePath(), passphrase, null, SQLiteDatabase.OPEN_READWRITE, null, null); final SQLiteStatement st=db.compileStatement("ATTACH DATABASE ? AS plaintext KEY ''"); st.bindString(1, newFile.getAbsolutePath()); st.execute(); db.rawExecSQL("SELECT sqlcipher_export('plaintext')"); db.rawExecSQL("DETACH DATABASE plaintext"); int version=db.getVersion(); st.close(); db.close(); db=SQLiteDatabase.openDatabase(newFile.getAbsolutePath(), "", null, SQLiteDatabase.OPEN_READWRITE); db.setVersion(version); db.close(); originalFile.delete(); newFile.renameTo(originalFile); } else { throw new FileNotFoundException(originalFile.getAbsolutePath()+" not found"); } }