對(duì)數(shù)據(jù)加密分兩種,一種是對(duì)數(shù)據(jù)庫(kù)本身進(jìn)行加密,另一種是對(duì)數(shù)據(jù)表中的數(shù)據(jù)進(jìn)行加密,
如果sqlite數(shù)據(jù)庫(kù)加密,我這里使用的一個(gè)管理工具叫sqlitedeveloper,如下就可以加密數(shù)據(jù)庫(kù)
,
如果在工具中不提供密碼的情況下打開(kāi)數(shù)據(jù)庫(kù),會(huì)給你錯(cuò)誤提示如下:
,
或者在c# 使用錯(cuò)誤的密碼也會(huì)給你錯(cuò)誤提示:
system.data.sqlite.sqliteexception:“file is encrypted or is not a database
,
正確的連接方式就是在連接字符串中提供正確的密碼:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
using system; using system.collections.generic; using system.data.sqlite; using system.linq; using system.text; using system.threading.tasks; namespace opensqlitedbbypwd { class program { static void main(string[] args) { string db_path = "data source=encrypteddb.db3; password=1111" ; using (sqliteconnection con = new sqliteconnection(db_path)) { con. open (); string sqlstr = @ "insert into customer(cust_no,customer) values ( 3001, 'allen' )" ; using (sqlitecommand cmd = new sqlitecommand(sqlstr, con)) { cmd.executenonquery(); } } } } } |
總結(jié)
以上所述是小編給大家介紹的c#連接加密的sqlite數(shù)據(jù)庫(kù)的方法,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)服務(wù)器之家網(wǎng)站的支持!
原文鏈接:http://www.cnblogs.com/LittleFeiHu/archive/2017/08/03/7279259.html