我必须面对一个新的小项目.它将有大约7或9个表,其中最大的表将以每月1000行的最大速率增长.
我认为SQLite是我的数据库......但是如果有人想要从数据库中更改数据,我将需要保护数据库
我的主要问题是:
是否可以像访问时那样使用密码保护sqlite数据库?
对于如此小的解决方案,您会推荐哪些其他RDBMS?
开发将在C#上,但我正在寻找一些免费的东西.
Man*_*esh 68
您可以使用密码保护SQLite3 DB.在进行任何操作之前,首次按如下方式设置密码.
SQLiteConnection conn = new SQLiteConnection("Data Source=MyDatabase.sqlite;Version=3;");
conn.SetPassword("password");
conn.Open();
Run Code Online (Sandbox Code Playgroud)
然后下次你可以访问它
conn = new SQLiteConnection("Data Source=MyDatabase.sqlite;Version=3;Password=password;");
conn.Open();
Run Code Online (Sandbox Code Playgroud)
这不允许任何GUI编辑器查看您的数据.如果您提供密码,某些编辑者可以解密数据库.使用的算法是RSA.
稍后如果您想更改密码,请使用
conn.ChangePassword("new_password");
Run Code Online (Sandbox Code Playgroud)
要重置或删除密码,请使用
conn.ChangePassword(String.Empty);
Run Code Online (Sandbox Code Playgroud)
Lir*_*evi 32
You can use the built-in encryption of the sqlite .net provider (System.Data.SQLite). See more details at http://web.archive.org/web/20070813071554/http://sqlite.phxsoftware.com/forums/t/130.aspx
To encrypt an existing unencrypted database, or to change the password of an encrypted database, open the database and then use the ChangePassword() function of SQLiteConnection:
// Opens an unencrypted database
SQLiteConnection cnn = new SQLiteConnection("Data Source=c:\\test.db3");
cnn.Open();
// Encrypts the database. The connection remains valid and usable afterwards.
cnn.ChangePassword("mypassword");
Run Code Online (Sandbox Code Playgroud)
To decrypt an existing encrypted database call ChangePassword() with a NULL or "" password:
// Opens an encrypted database
SQLiteConnection cnn = new SQLiteConnection("Data Source=c:\\test.db3;Password=mypassword");
cnn.Open();
// Removes the encryption on an encrypted database.
cnn.ChangePassword(null);
Run Code Online (Sandbox Code Playgroud)
To open an existing encrypted database, or to create a new encrypted database, specify a password in the ConnectionString as shown in the previous example, or call the SetPassword() function before opening a new SQLiteConnection. Passwords specified in the ConnectionString must be cleartext, but passwords supplied in the SetPassword() function may be binary byte arrays.
// Opens an encrypted database by calling SetPassword()
SQLiteConnection cnn = new SQLiteConnection("Data Source=c:\\test.db3");
cnn.SetPassword(new byte[] { 0xFF, 0xEE, 0xDD, 0x10, 0x20, 0x30 });
cnn.Open();
// The connection is now usable
Run Code Online (Sandbox Code Playgroud)
默认情况下,将另一个数据库文件附加到现有连接时,ATTACH关键字将使用与主数据库相同的加密密钥.若要更改此行为,请使用KEY修饰符,如下所示:
如果使用明文密码附加加密数据库:
// Attach to a database using a different key than the main database
SQLiteConnection cnn = new SQLiteConnection("Data Source=c:\\test.db3");
cnn.Open();
cmd = new SQLiteCommand("ATTACH DATABASE 'c:\\pwd.db3' AS [Protected] KEY 'mypassword'", cnn);
cmd.ExecuteNonQuery();
Run Code Online (Sandbox Code Playgroud)
使用二进制密码附加加密数据库:
// Attach to a database encrypted with a binary key
SQLiteConnection cnn = new SQLiteConnection("Data Source=c:\\test.db3");
cnn.Open();
cmd = new SQLiteCommand("ATTACH DATABASE 'c:\\pwd.db3' AS [Protected] KEY X'FFEEDD102030'", cnn);
cmd.ExecuteNonQuery();
Run Code Online (Sandbox Code Playgroud)
小智 12
使用SQLCipher,它是SQLite的开源扩展,为数据库文件提供透明的256位AES加密.http://sqlcipher.net