Decrypting an existing SQL Cipher Database in C# .NET


#1

Hi,

I have an SQL CIPHER encrypted db. All i want to do is remove the password from the encrypted db programtically in .NET . i tried using change password method and passed empty string it didint work but threw an exception.

The steps i took to decrypt was:

  1. Establish the connection to encrypted db with the password.
  2. When i use ChangePassword method of Sqlite and pass empty string its throwing an exception.

The code I wrote was

SQLiteConnection conn = new SQLiteConnection(“Data Source=database.db”);
conn.SetPassword(“test”);
conn.Open();
conn.changePassword(""); or conn.changePassword(String.Empty);

This will throw the exception details mentioned below.

Exception :
threw an exception of type 'System.Data.SQLite.SQLiteException’
base: {“SQL logic error or missing database\r\nnot an error”}
ErrorCode: 1
ResultCode: Error

So how should i remove the password from the db programtically ?


#2

Hello @TEJASVI_N

To export a plain text version of a SQLCipher encrypted database, you would need to use the sqlcipher_export convenience function, in your case, example # 2 is the scenario you will want to apply.


#3

Does it mean decryption grammatically in .net is not supported?


#4

Set password is useful because it calls native method of key().
But sqlcipher can only decrypt database which encrypted by sqlcipher.


#5

You could find out the sqlite.dll, and replace it by another sqlite3.dll which generated by sqlcipher.
Than, use command.ExecuteNoQuery() to execute SQL : sqlcipher_export and other necessary SQL.
You could search: how to encrypt a existed dB using sqlcipher.