Skip to content

non-encrypted db not being created by net.sqlcipher.database.SQLiteDatabase. #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
iffrah19 opened this issue Jul 4, 2013 · 6 comments

Comments

@iffrah19
Copy link

iffrah19 commented Jul 4, 2013

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?.

@ghost
Copy link

ghost commented Jul 5, 2013

@iffrah19
Copy link
Author

iffrah19 commented Jul 5, 2013

Hi,
thanks for the response. how do I decrypt and open an encrypted sqlite db.

I'm using command line to check this but the sqlite3 in android sdk does not supports net.sqlcipher.database.SQLiteDatabase. So, maybe it shows every database created by sqlcipher as encrypted.

@n8fr8
Copy link
Collaborator

n8fr8 commented Jul 5, 2013

Why don't you just use the standard Android Database API to create the unencrypted database? We designed the SQLCipher API to be as interoperable as possible with standard Cursors and the like, so there is very little difference in the code. You just need a helper class to call the specific database setup API, either the SQLCIpher package or the stock android.database.

@n8fr8
Copy link
Collaborator

n8fr8 commented Jul 5, 2013

By specifying an empty string as "" in the argument, you are actually just setting the key to an empty string, like a blank password. This will create an encrypted database, as you discovered, with a blank password, and not an unencrypted database.

@iffrah19
Copy link
Author

I got my answer. Using empty string string as password does creates non-encrypted db. My problem was that I was using command line(sqlite3 in sdk) 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.

@developernotes
Copy link
Member

Hi iffrah19,

You can use a SQLCipher shell to interact with both a SQLite or a SQLCipher database. Instructions for building it can be found here. I am unaware of SQLCipher support in Lita.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants