0

My app works with an already provided DB. I generate this one manually with a sqlite script and I put it on the asset folder of my android studio project.

I want to encrypt it and working with it using SQLCipher. I already implemented it on my android app, but I need to encrypt my DB BEFORE putting it on the asset folder, in order to provide the users with an already encrypted DB I can use using SQLCipher.

How can I do this? Thanks in advance.

1 Answer 1

1

You can create an encrypted SQLCipher database using the SQLCipher command line shell:

./sqlcipher foo.db
sqlcipher> PRAGMA key = 'foo';
sqlcipher> CREATE TABLE t1(a,b);
sqlcipher> INSERT INTO t1(a,b) VALUES('one for the money', 'two for the show');
sqlcipher> .q

You can find documentation on creating the SQLCipher shell here. Alternatively, if you already have the database, you can use the sqlcipher_export(...) convenience function to export a plain text database to a SQLCipher encrypted file. You can run the sqlcipher_export function either through the SQLCipher command line shell, or programmatically on your Android device using SQLCipher for Android.

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

1 Comment

Hi Nick. Thanks for your answer. For the moment I'm using an already existing DB as a .db file. But on the next versions of my app, the DB will be re-generated using a SQL script I created myself. Is there a way to implement the encryption method directly in it?

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.