# Decrypting an existing SQL Cipher Database in C# .NET

**URL:** <https://discuss.zetetic.net/t/decrypting-an-existing-sql-cipher-database-in-c-net/578>\
**Category:** SQLCipher\
**Created:** [May 23, 2015, 8:44am UTC](https://discuss.zetetic.net/t/decrypting-an-existing-sql-cipher-database-in-c-net/578 "2015-05-23T08:44:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![TEJASVI\_N](https://avatars.discourse-cdn.com/v4/letter/t/ecc23a/32.png) [@TEJASVI\_N](https://discuss.zetetic.net/u/TEJASVI_N)\
**Post date:** [May 23, 2015, 8:44am UTC](https://discuss.zetetic.net/t/decrypting-an-existing-sql-cipher-database-in-c-net/578/1 "2015-05-23T08:44:53Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![developernotes](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/developernotes/32/1309_2.png) [@developernotes](https://discuss.zetetic.net/u/developernotes)\
**Post date:** [May 26, 2015, 1:16pm UTC](https://discuss.zetetic.net/t/decrypting-an-existing-sql-cipher-database-in-c-net/578/2 "2015-05-26T13:16:30Z")

</div>

Hello @TEJASVI_N

To export a plain text version of a SQLCipher encrypted database, you would need to use the [`sqlcipher_export`](https://www.zetetic.net/sqlcipher/sqlcipher-api/#sqlcipher_export) convenience function, in your case, example # 2 is the scenario you will want to apply.

---

<div class="post-metadata">

**Author:** ![Maha\_Saad](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Maha\_Saad](https://discuss.zetetic.net/u/Maha_Saad)\
**Post date:** [July 14, 2015, 11:42am UTC](https://discuss.zetetic.net/t/decrypting-an-existing-sql-cipher-database-in-c-net/578/3 "2015-07-14T11:42:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![LiMingjian](https://avatars.discourse-cdn.com/v4/letter/l/9e8a1a/32.png) [@LiMingjian](https://discuss.zetetic.net/u/LiMingjian)\
**Post date:** [February 27, 2016, 3:14am UTC](https://discuss.zetetic.net/t/decrypting-an-existing-sql-cipher-database-in-c-net/578/4 "2016-02-27T03:14:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![LiMingjian](https://avatars.discourse-cdn.com/v4/letter/l/9e8a1a/32.png) [@LiMingjian](https://discuss.zetetic.net/u/LiMingjian)\
**Post date:** [February 27, 2016, 3:20am UTC](https://discuss.zetetic.net/t/decrypting-an-existing-sql-cipher-database-in-c-net/578/5 "2016-02-27T03:20:23Z")

</div>

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.
