Regarding rey key

92 views
Skip to first unread message

A sayyad

unread,
Jul 29, 2012, 7:42:22 AM7/29/12
to sqlc...@googlegroups.com
I created one database with empty string("").It works fine & database created is unencrypted.

Then I rekeyed the database with some password new.

String password ="";
String str = "PRAGMA key = "+"'"+password+"'";
db.rawExecSQL(str);
str = "PRAGMA rekey = "+"'"+"new"+"'";
db.rawExecSQL(str);

Now when I again open the database with new password, I am getting exception as below

net.sqlcipher.database.SQLiteException: file is encrypted or is not a database
.

However if I open the database with empty string.It works fine--

Note - This is happening only when I create  the  database with empty string then try to rekey it with some password.

If I create the database initially with some password & then try to rekey it with some other password, it works perfectly fine..

Nick Parker

unread,
Jul 30, 2012, 9:08:48 AM7/30/12
to sqlc...@googlegroups.com, A sayyad
Hi,

PRAMA rekey can not be used to encrypt a standard SQLite database, which is what you have when you issued your PRAGMA key with a blank password.  You would need to use sqlcipher_export() [1] to perform that type of conversion.

1.  http://sqlcipher.net/sqlcipher-api/#sqlcipher_export
-- 
Nick Parker

Nick Parker

unread,
Jul 30, 2012, 12:23:23 PM7/30/12
to ashiq sayyad, sqlc...@googlegroups.com
Hi Ashiq,

No, you can of course delete the old unencrypted database once the export has completed to minimize disk space usage.

On 7/30/12 10:31 AM, ashiq sayyad wrote:
Thanks Nick.
I have created database initially using sqlcipher APIS only using empty string.Now I want  to rekey it with some password.


I tried exporting option.It works but it will create new db which will copy data from plain text db into the new encrypted db.
Is there any way to encrypt the same db without creating new one?????????

-- 
Nick Parker

Nick Parker

unread,
Jul 31, 2012, 10:38:22 AM7/31/12
to ashiq sayyad, sqlc...@googlegroups.com
Hi Ashiq,

You need to verify that your 'db' instance is referencing an open connection to the unencrypted database before you perform this process.  An example of doing this is provided in our test suite here [1] that you can run.

1.  https://github.com/sqlcipher/sqlcipher-android-tests/blob/master/src/main/java/net/zetetic/tests/ImportUnencryptedDatabaseTest.java

On 7/31/12 4:45 AM, ashiq sayyad wrote:
I exported the plain text database to encrypted database using following commands--

String str = "ATTACH DATABASE '/data/data/com.salciphersampleapp/databases/encrypted' AS encrypted KEY 'testkey'";
db.rawExecSQL(str);
str ="SELECT sqlcipher_export('encrypted')"; 
db.rawExecSQL(str);
str =  "DETACH DATABASE encrypted"; 
db.rawExecSQL(str);

It created database with name encrypted But it does not have any data exported from old plain text database...

-- 
Nick Parker
Reply all
Reply to author
Forward
0 new messages