5

I want to create a new encrypted database with SQLCipher, I didn't really undestand how to set a key due to the following link: http://sqlcipher.net/sqlcipher-api/#key

As the documentation explains, I have to set a key with PRAGMA, but from where do I excecute that command?

2 Answers 2

3

For Android, you just need to call openOrCreateDatabase to provide the encryption key. The second parameter is the passphrase that will be used.

SQLiteDatabase database = SQLiteDatabase.openOrCreateDatabase(databaseFile, "test123", null);

The "PRAGMA key" interface provides the same function when using the command line version of SQLCipher.

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

Comments

1

you should read this: sqlcipher.net/introduction The build instructions should get you a utility which will be the command line shell (based on sqlLite) for SQLCipher.

4 Comments

You link led me to the following link (as I'm using it in Android application) and it says nothing about defining PRAGMA key: sqlcipher.net/sqlcipher-for-android
From what I have read in the documentation, you can run the PRAGMA command just like you would run any sql query on the DB. You can maybe try using the execSQL method (the same method you will use to run sqls from within your android code) and give the PRAGMA command as the argument. See the code example in the link you mentioned.
You said I can run the PRAGMA command just like I run any sql query on the DB, and I'm doing it through code in JAVA (not through some interface or something) so I still don't understand how can I run it. Edit: I prefer not to use the execSQL command.
I am not sure if you can use something else apart from the execSQL method. Since sqlCipher is based on sqlLite, you have to use the methods provided by sqlLite.

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.