对数据加密分两种,一种是对数据库本身进行加密,另一种是对数据表中的数据进行加密,
如果SQLite数据库加密,我这里使用的一个管理工具叫SQLiteDeveloper,如下就可以加密数据库
 ,
,
如果在工具中不提供密码的情况下打开数据库,会给你错误提示如下:
 ,
,
或者在C# 使用错误的密码也会给你错误提示:
 ,
,
正确的连接方式就是在连接字符串中提供正确的密码:
class="brush:csharp;gutter:true;">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();
                }
            }
        }
    }
}