3

I want to use C# (winform) to read an SQLCipher database and find an open source project SQLitePCL, but I have not found examples of this use, and the documentation is not a lot. Have any friends used this thing, can you provide some examples to help me?

Thank you!

2

1 Answer 1

5

This will work for winforms, wpf, asp.net, xamarin.android, xamarin.ios, UWP and any other .net project since this is a cross-platform library:

Install nuget by Frank A. Krueger "sqlite-net-pcl".

Use tutorial from his github page.

Now, once we have database and all the stuff. How to encrypt newly created database or open encrypted database?

Add nuget by Eric Sink: "SQLitePCLRaw.bundle_sqlcipher"

In the code, where you create SQLiteConnection specify encryption key:

connection = new SQLiteConnection(dbPath, openFlags: SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.FullMutex | SQLiteOpenFlags.Create);
connection.Query<int>("PRAGMA key=xzy1921");

That's it. The rest will work as if it was not crypted.

Sign up to request clarification or add additional context in comments.

8 Comments

I should use it in winform program . Error The package "sqlite-net-pcl 1.4.118" could not be installed. You are trying to install this package into a project with the target ".NETFramework, Version=v3.5", but the package does not contain any assembly references or content files that are compatible with the framework. For more information, please contact the package author. 0
Don't use .net 3.5. Update you winforms app to use .NET 4.7
Add nuget by Eric Sink: "SQLitePCLRaw.bundle_sqlcipher" 。 What special operations are needed after that? SQLite.SQLiteException:“file is not a database”
@诺倾情 It means that you are trying to open database with password even though it's not encrypted. Or you open encrypted database without password or with incorrect one.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.