C#訪問加密的SQLite資料庫

來源:互聯網
上載者:User

標籤:

 

 

前提:一個項目需要儲存各種密碼資料,使用的嵌入式的SQLite資料庫。預設的SQLite資料庫是沒有加密的,這樣相當不安全。找呀找呀找方法。。。

方法:

  1。使用SQLite管理器加密。

    部分SQLite管理器是有對SQLite資料庫有加密功能的。本小菜使用的是:SQLite Developer管理工具。加密如下:

          

    密碼就設定OK了。

  2.C#訪問SQLite帶密碼的資料庫

    首先說說,不帶密碼的SQLite訪問字串格式,只需寫入資料庫所在路徑即可:

    string ConnStr= "Data Source=F:/sqlitedb/test.db";

    訪問帶密碼以為比較複雜,結果很簡單,加入Password參數即可:

    string ConnStr= "Data Source=F:/sqlitedb/test.db; Password=123";

 

範例程式碼,親測有效:

 

 1 string DB_PATH = "Data Source=F:/sqlitedb/test.db; Password=123"; 2  3         private void add_Click(object sender, RoutedEventArgs e) 4         {     5             using (SQLiteConnection con = new SQLiteConnection(DB_PATH)) 6             { 7                 con.Open(); 8                 string sqlStr = @"INSERT INTO hero 9                                   VALUES10                                   (11                                       3,12                                       ‘測試有效‘13                                   )";14                 using (SQLiteCommand cmd = new SQLiteCommand(sqlStr, con))15                 {16                     cmd.ExecuteNonQuery();17                 }18             }19         }
View Code

 

C#訪問加密的SQLite資料庫

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.