我可以用密码加密SQLite数据库吗?

Has*_*ion 17 c# sql database sqlite

我使用SQLite数据库版本3与C#Windows应用程序..我想使用密码或任何其他加密方式加密SQLite数据库文件,以防止客户端从程序文件文件夹中打开它.

我不想要任何运行时加密方式,我只想在客户端尝试从程序文件中打开它时使数据库文件显示密码字段..谢谢

编辑

如果我从代码加密它,客户端可以在安装完成后打开它并将db文件传输到程序文件,然后再打开程序执行加密不是吗?

Lui*_*ado 24

我使用SQLite版本3完美运行!你必须这样做:

//if the database has already password
try{
            string conn = @"Data Source=database.s3db;Password=Mypass;";
            SQLiteConnection connection= new SQLiteConnection(conn);
            connection.Open();
            //Some code
            connection.ChangePassword("Mypass");
            connection.Close();
    }
//if it is the first time sets the password in the database
catch
    {
            string conn = @"Data Source=database.s3db;";
            SQLiteConnection connection= new SQLiteConnection(conn);
            connection.Open();
            //Some code
            connection.ChangePassword("Mypass");
            connection.Close();
    }
Run Code Online (Sandbox Code Playgroud)

此后如果用户试图打开数据库.会说管理员受保护或者数据库是加密的,还是不是数据库或损坏的文件!