Good afternoon,
I am evaluating SQLCipher encryption. I have an existing database with data that has never been encrypted, and now want to change it to a SQLCipher encrypted database. Can you please help with some example code?
I have followed the example at https://www.devart.com/dotconnect/SQLit ... ipher.html, but when I try to apply this to my existing database, the code fails.
New SQLCipher encryption
-
- Devart Team
- Posts: 2420
- Joined: Wed 02 Nov 2011 09:44
Re: New SQLCipher encryption
Please send us the message and stack trace of the exception and all inner exceptions.
Please also make sure that your application uses the sqlite3.dll library with the SQLCipher extension, and that the library has the same capacity (32bit or 64bit) as your application.
Please also make sure that your application uses the sqlite3.dll library with the SQLCipher extension, and that the library has the same capacity (32bit or 64bit) as your application.
-
- Posts: 8
- Joined: Mon 09 Sep 2013 07:11
Re: New SQLCipher encryption
Good morning,
I have sent an email to explain the behaviour. Please let me know what I can do to fix the issue.
I have sent an email to explain the behaviour. Please let me know what I can do to fix the issue.
Re: New SQLCipher encryption
The conn.ChangePassword("best2") method runs
cmd = New SQLiteCommand("PRAGMA rekey='best2'", conn)
cmd.ExecuteNonQuery()
underneath. In its turn, the PRAGMA rekey command requires the database to be already ENCRYPTED, i.e. be created with SQLCipher's SQLite.Interop.dll. Looks like your databaseOld.db database was created with a standard plaintext sqlite3.dll.
To fix the problem, export existing plaintext databaseOld.db to a new encrypted database file:
cmd = New SQLiteCommand("PRAGMA rekey='best2'", conn)
cmd.ExecuteNonQuery()
underneath. In its turn, the PRAGMA rekey command requires the database to be already ENCRYPTED, i.e. be created with SQLCipher's SQLite.Interop.dll. Looks like your databaseOld.db database was created with a standard plaintext sqlite3.dll.
To fix the problem, export existing plaintext databaseOld.db to a new encrypted database file:
Code: Select all
Sub EncryptPlainTextDb(existing As String, newEncrypted As String)
' the ATTACH DATABASE command will create a file specified in the newEncrypted path
Using conn As New SQLiteConnection("FailIfMissing = true; Data Source=" + existing)
conn.Open()
Dim cmd = conn.CreateCommand()
cmd.CommandText = "ATTACH DATABASE '" + newEncrypted + "' AS encrypted KEY 'mypassword'"
cmd.ExecuteNonQuery()
cmd.CommandText = "SELECT sqlcipher_export('encrypted')"
cmd.ExecuteNonQuery()
cmd.CommandText = "DETACH DATABASE encrypted"
cmd.ExecuteNonQuery()
End Using
End Sub
-
- Posts: 8
- Joined: Mon 09 Sep 2013 07:11
Re: New SQLCipher encryption
Good morning,
Thank you very much for the response. The below enabled me to resolve the issue.
I really appreciate the help.
Regards,
Johann
Thank you very much for the response. The below enabled me to resolve the issue.
I really appreciate the help.
Regards,
Johann
Re: New SQLCipher encryption
The SQLiteConnection.SQLCipherExport() method is added to migrate from an existing non-encrypted database to a new encrypted one in the newest (5.3.478) build of dotConnect for SQLite: http://forums.devart.com/viewtopic.php?f=29&t=32321.
Here is an example:
Here is an example:
Code: Select all
using (var conn = new SQLiteConnection()) {
conn.ConnectionString = @"Data Source=D:\databaseOld.db;Encryption = SQLCipher;";
conn.Open();
conn.SQLCipherExport(@"D:\databaseNew.db", "11111");
}