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?

idish
  • 3,190
  • 12
  • 53
  • 85

2 Answers2

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.

Stephen Lombardo
  • 1,503
  • 8
  • 7
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.

Aditya K
  • 487
  • 3
  • 11
  • You link led me to the following link (as I'm using it in Android application) and it says nothing about defining PRAGMA key: http://sqlcipher.net/sqlcipher-for-android/ – idish Nov 20 '12 at 18:40
  • 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. – Aditya K Nov 20 '12 at 18:53
  • 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. – idish Nov 20 '12 at 19:16
  • 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. – Aditya K Nov 22 '12 at 04:24