Java Code Examples for net.sqlcipher.database.SQLiteDatabase#loadLibs()

The following examples show how to use net.sqlcipher.database.SQLiteDatabase#loadLibs() . 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
@Test
public void safe() {
  final Context ctxt=InstrumentationRegistry.getTargetContext();

  SQLiteDatabase.loadLibs(ctxt);
  SQLiteOpenHelper helper = new SafeNonRoomHelper(ctxt);

  helper.getWritableDatabase(PASSPHRASE);
  helper.close();

  ImportingSafeDatabase room = ImportingSafeDatabase.gimme(ctxt);
  SupportSQLiteDatabase db=room.getOpenHelper().getWritableDatabase();

  try {
    assertTrue(db.isWriteAheadLoggingEnabled());
  }
  finally {
    room.close();
  }
}
 
Example 2
/**
   * Gets a writable SQLiteDatabase object
   * 
   * @return The SQLiteDatabase object
   */
  public static SQLiteDatabase openDatabase()
  {
  	Log.i(TAG, "DatabaseContentProvider.openDatabase() called");
  	
  	try
  	{
  		SQLiteDatabase.loadLibs(sContext);
  		sDatabase = sDatabaseHelper.getWritableDatabase();
  	}
  	catch (Exception e)
  	{
  		Log.e(TAG, "Exception occurred while running DatabaseContentProvider.openDatabase(). The exception message was:\n" 
  				+ e.getMessage());
  	}
  	
return sDatabase;
  }
 
Example 3
private DatabaseFactory(@NonNull Context context) {
  SQLiteDatabase.loadLibs(context);

  DatabaseSecret      databaseSecret   = new DatabaseSecretProvider(context).getOrCreateDatabaseSecret();
  AttachmentSecret    attachmentSecret = AttachmentSecretProvider.getInstance(context).getOrCreateAttachmentSecret();

  this.databaseHelper       = new SQLCipherOpenHelper(context, databaseSecret);
  this.sms                  = new SmsDatabase(context, databaseHelper);
  this.mms                  = new MmsDatabase(context, databaseHelper);
  this.attachments          = new AttachmentDatabase(context, databaseHelper, attachmentSecret);
  this.media                = new MediaDatabase(context, databaseHelper);
  this.thread               = new ThreadDatabase(context, databaseHelper);
  this.mmsSmsDatabase       = new MmsSmsDatabase(context, databaseHelper);
  this.identityDatabase     = new IdentityDatabase(context, databaseHelper);
  this.draftDatabase        = new DraftDatabase(context, databaseHelper);
  this.pushDatabase         = new PushDatabase(context, databaseHelper);
  this.groupDatabase        = new GroupDatabase(context, databaseHelper);
  this.recipientDatabase    = new RecipientDatabase(context, databaseHelper);
  this.groupReceiptDatabase = new GroupReceiptDatabase(context, databaseHelper);
  this.contactsDatabase     = new ContactsDatabase(context);
  this.preKeyDatabase       = new OneTimePreKeyDatabase(context, databaseHelper);
  this.signedPreKeyDatabase = new SignedPreKeyDatabase(context, databaseHelper);
  this.sessionDatabase      = new SessionDatabase(context, databaseHelper);
  this.searchDatabase       = new SearchDatabase(context, databaseHelper);
  this.jobDatabase          = new JobDatabase(context, databaseHelper);
  this.stickerDatabase      = new StickerDatabase(context, databaseHelper, attachmentSecret);
  this.storageKeyDatabase   = new StorageKeyDatabase(context, databaseHelper);
  this.keyValueDatabase     = new KeyValueDatabase(context, databaseHelper);
  this.megaphoneDatabase    = new MegaphoneDatabase(context, databaseHelper);
}
 
Example 4
@Override
public void onCreate() {
    super.onCreate();
    initInjector();

    try {
        SQLiteDatabase.loadLibs(this);
    } catch (UnsatisfiedLinkError e) {
        //only thrown during tests, ignore it
    }
}
 
Example 5
Source Project: android-security   File: SecurityApp.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    Hawk.init(this).build();
    SQLiteDatabase.loadLibs(this);

    int times = Hawk.get(PREF_TIMES, 0) + 1;
    Log.d(TAG, "Psss! Let me tell a secret: you opened this app " + times + " times.");
    Hawk.put(PREF_TIMES, times);
}
 
Example 6
Source Project: cwac-saferoom   File: SQLCipherUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 7
Source Project: cwac-saferoom   File: SQLCipherUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 8
Source Project: cwac-saferoom   File: Helper.java    License: Apache License 2.0 5 votes vote down vote up
Helper(Context context, String name, Callback callback, byte[] passphrase,
       SafeHelperFactory.Options options) {
  SQLiteDatabase.loadLibs(context);
  clearPassphrase=options.clearPassphrase;
  delegate=createDelegate(context, name, callback, options);
  this.passphrase=passphrase;
}
 
Example 9
@Override
protected void onRunSetup() throws Exception {
    super.onRunSetup();

    // set up database
    SQLiteDatabase.loadLibs(getTargetContext());
    DbHelper dbHelper = new DbHelper(getTargetContext(), DATABASE_NAME, DATABASE_VERSION);
    database = dbHelper.getWritableDatabase(DATABASE_PASSWORD);
}
 
Example 10
Source Project: kripton   File: KriptonSQLCipherHelper.java    License: Apache License 2.0 5 votes vote down vote up
KriptonSQLCipherHelper(Context context, String name, Callback callback, byte[] passphrase,
		KriptonSQLCipherHelperFactory.Options options) {
	SQLiteDatabase.loadLibs(context);
	clearPassphrase = options.clearPassphrase;
	delegate = createDelegate(context, name, callback, options);
	this.passphrase = passphrase;
	this.requiredPassphrase = options.requiredPassphrase;
}
 
Example 11
Source Project: kripton   File: SQLCipherUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 12
public static void init(Context context) {
    SQLiteDatabase.loadLibs(context);
    File file = new File(context.getFilesDir().getPath() + "EnMicroMsg0.db");

}
 
Example 13
Source Project: alchemy   File: SQLCipherDbTest.java    License: Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void loadJni() {
    SQLiteDatabase.loadLibs(InstrumentationRegistry.getContext());
}
 
Example 14
Source Project: alchemy   File: AlchemySQLCipher4aTest.java    License: Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void loadJni() {
    SQLiteDatabase.loadLibs(InstrumentationRegistry.getContext());
}
 
Example 15
@Override
public SQLiteDB create(Context context, String path, String password) {
    SQLiteDatabase.loadLibs(context);
    return new DebugEncryptSQLiteDB(SQLiteDatabase.openOrCreateDatabase(path, password, null));
}
 
Example 16
public PersonDBHelper(Context context) {

        super(context, DATABASE_NAME, null, 1);
        SQLiteDatabase.loadLibs(context);
    }
 
Example 17
EncryptedDatabaseOpenHelper(Context context, String databaseName, int targetVersion) {
    super(context, databaseName, null, targetVersion, hook);
    SQLiteDatabase.loadLibs(context);
    this.baseHelper = new BaseDatabaseOpenHelper(context, targetVersion);
}
 
Example 18
@Override
public void onCreate() {
    super.onCreate();

    turnOnStrictMode();

    CommCareApplication.app = this;
    CrashUtil.init();
    DataChangeLogger.init(this);

    logFirstCommCareRun();
    CommCarePreferenceManagerFactory.init(new AndroidPreferenceManager());

    configureCommCareEngineConstantsAndStaticRegistrations();
    initNotifications();

    //TODO: Make this robust
    PreInitLogger pil = new PreInitLogger();
    Logger.registerLogger(pil);

    // Workaround because android is written by 7 year-olds (re-uses http connection pool
    // improperly, so the second https request in a short time period will flop)
    System.setProperty("http.keepAlive", "false");

    initTls12IfNeeded();

    Thread.setDefaultUncaughtExceptionHandler(new CommCareExceptionHandler(Thread.getDefaultUncaughtExceptionHandler(), this));

    SQLiteDatabase.loadLibs(this);

    setRoots();

    prepareTemporaryStorage();

    if (LegacyInstallUtils.checkForLegacyInstall(this)) {
        dbState = STATE_LEGACY_DETECTED;
    } else {
        // Init global storage (Just application records, logs, etc)
        dbState = initGlobalDb();
    }

    setupLoggerStorage(false);
    pil.dumpToNewLogger();

    initializeDefaultLocalizerData();

    if (dbState != STATE_MIGRATION_FAILED && dbState != STATE_MIGRATION_QUESTIONABLE) {
        AppUtils.checkForIncompletelyUninstalledApps();
        initializeAnAppOnStartup();
    }

    LocalePreferences.saveDeviceLocale(Locale.getDefault());
}
 
Example 19
Source Project: cwac-saferoom   File: SQLCipherUtils.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Determine whether or not this database appears to be encrypted, based
 * on whether we can open it without a passphrase.
 *
 * @param ctxt a Context
 * @param dbName the name of the database, as used with Room, SQLiteOpenHelper,
 *               etc.
 * @return the detected state of the database
 */
public static State getDatabaseState(Context ctxt, String dbName) {
  SQLiteDatabase.loadLibs(ctxt);

  return(getDatabaseState(ctxt.getDatabasePath(dbName)));
}
 
Example 20
Source Project: kripton   File: SQLCipherUtils.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Determine whether or not this database appears to be encrypted, based
 * on whether we can open it without a passphrase.
 *
 * @param ctxt a Context
 * @param dbName the name of the database, as used with Room, SQLiteOpenHelper,
 *               etc.
 * @return the detected state of the database
 */
public static State getDatabaseState(Context ctxt, String dbName) {
  SQLiteDatabase.loadLibs(ctxt);

  return(getDatabaseState(ctxt.getDatabasePath(dbName)));
}