1

In my android app, I need to give user an option to create an encrypted or non-encrypted database; The database will be saved in device sdcard.

For the non-encrypted db I'm using :-

db = SQLiteDatabase.openOrCreateDatabase(DB_PATH + DB_NAME, "", null);

but when I open the db through command line,it gives error: file is encrypted or is not a database. So the above code line always creates encrypted database.

My code is below:

if(db == null){
    try{
        SQLiteDatabase.loadLibs(context);
        String encryptStr = "";

        if(new File(DB_PATH + DB_NAME).exists()){
            db = SQLiteDatabase.openOrCreateDatabase(DB_PATH + DB_NAME, encryptStr, null);
        }else{

            db = SQLiteDatabase.openOrCreateDatabase(DB_PATH + DB_NAME, encryptStr,          null);
            executeSchema(context);
        }

        db.setVersion(1);
        db.setLocale(Locale.getDefault());
        db.setLockingEnabled(true);
    }catch(Exception e){
        db = null;
        AlertHelper.logError(e);
    }
}

Any way to create non-encrypted database using sqlcipher in android?.

2 Answers 2

1

I got my answer. Using empty string string as password does creates non-encrypted db. My problem was that I was using command line to check db; It does not supports sqlcipher.database so it always returned db as encrypted.

I pulled my db from device using 'pull' button in eclpise and then opened it in Lita(software for viewing db). The db with empty key opens up but with non-empty key it tells that db is encrypted and thus can't be opened.

Sign up to request clarification or add additional context in comments.

Comments

0

are you sure you have used the right method? I couldn't find the

db = SQLiteDatabase.openOrCreateDatabase(DB_PATH + DB_NAME, "", null);

method,

I just see these methods:

SQLiteDatabase.openOrCreateDatabase(file, factory)

SQLiteDatabase.openOrCreateDatabase(path, factory)

SQLiteDatabase.openDatabase(path, factory, flags)

1 Comment

I'm importing net.sqlcipher.database.SQLiteDatabase; and using SQLiteDatabase.openOrCreateDatabase (String path, String password, CursorFactory factory)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.