SQLite encryption method (c #)

Original: the SQLite encryption method (c #)

http://blog.csdn.net/xjbx/article/details/2712236

Settings password on it

nbsp;

http://bbs.csdn.net/topics/380018685

Compiled as a static library, and have the encryption?

CppSQLite3U

nbsp;

nbsp;

Recently doing a winform program, consider using Sqlite database, compact and functional, much stronger than Access, but needs to be encrypted, but the free version does not have encryption, there are some c ++ implementations: for example: HTTP: //www.sqlite . Com.cn / MySqlite /. 3 / 253.Html nbsp; and http://www.cppblog.com/niewenlong/archive/2007/06/01/25261.html nbsp ;. However, given that I am not proficient in c ++, so he uses ADO.NET 2.0 SQLite Data Providernbsp; so you can directly use it to create an encrypted sqlite database .
C # code related as follows:
1, create an empty database sqlite.


// name suffix database you can directly specify the suffix can not even

// Method One: Create an empty sqlite database with IO way

FileStream fsnbsp;=nbsp;File.Create("c://test.db");

// Method 2: SQLiteConnection

SQLiteConnection.CreateFile("c://test.db");

nbsp;

Database creation is a 0 byte file.

2, create an encrypted database empty sqlite


// Create a sqlite database password for the password empty

SQLiteConnection.CreateFile("c://test2.db");nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;

SQLiteConnection cnnnbsp;=nbsp;newnbsp;SQLiteConnection("Data Source=c://test2.db");

SQLiteConnection cnnnbsp;=nbsp;newnbsp;SQLiteConnection("Data Source=D://test2.db");

cnn.Open();

cnn.ChangePassword("password");

3, to an unencrypted database encryption


SQLiteConnection cnnnbsp;=nbsp;newnbsp;SQLiteConnection("Data Source=c://test.db");

cnn.Open();

cnn.ChangePassword("password");

4, opening an encrypted database sqlite

//method one

SQLiteConnection cnnnbsp;=nbsp;newnbsp;SQLiteConnection("Data Source=c://test2.db");

cnn.SetPassword("password");

cnn.Open();

//Method Two

SQLiteConnectionStringBuilder buildernbsp;=nbsp;newnbsp;SQLiteConnectionStringBuilder();

builder.DataSourcenbsp;=nbsp;@"c:/test.db";

builder.Passwordnbsp;=nbsp;@"password";

SQLiteConnection cnnnbsp;=nbsp;newnbsp;SQLiteConnection(builder.ConnectionString);

cnn .Open();

Note:
A, because the encryption function is to use windows api, so the encrypted database can only be applied in the windows platform, encryption is the way the whole file encryption.
B, the encryption algorithm is RC4 , if you want to use other encryption algorithms for encryption, please refer to the ADO.NET 2.0 SQLite Data Provider to modify the source code.
c, similar to database operations associated sqlite ADO.NET 2.0. See ADO.NET 2.0 SQLite Data Provider Help documentation.
c, ADO.NET 2.0 SQLite Data Provider version: 1.0.53.0, SQLite Version: 3.6.0.
d, development environment for vs2008.

Download the ADO.NET 2.0 SQLite Data Provider: http://sourceforge.net/project/showfiles.php?group_id=132486amp;package_id=145568

Sqlite about the Chinese introduction, you can look here: http://www.cnblogs.com/shanyou/archive/2007/01/08/615245.html

This article first appeared Address: http://www.watch-life.net/net-tip/sqlite-encrypted.html

More Articles See: Rye Xuan [ http://www.watch-life.net/ ]

nbsp;

Guess you like

Origin www.cnblogs.com/lonelyxmas/p/11247887.html