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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12190672/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 22:24:53  来源:igfitidea点击:

Can i password encrypt SQLite database?

c#sqldatabasesqlite

提问by Hassanation

I am using SQLite database version 3 with C# Windows application.. i want to encrypt the SQLite database file using password or any other encryption way in order to prevent clients to open it from program files folder.

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

i don't want any runtime encryption ways, i just want to make the database file show password field when a client try to open it from the program files .. thanks

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

Edit

编辑

and if i encrypted it from code,the client can open it when the installation complete and db file transferred to the program files before opening the program to perform the encryption isnt it?

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

采纳答案by Luis Granado

I use SQLite version 3 works perfectly! You have to do that:

我使用 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();
    }

thereafter if the user tries to open the database. will say protected by Admin or the database is encrypted or is not a database or corrupted file!

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

回答by Nikhil Agrawal

Unfortunately, password in SQlite file can be added or removed or changed only from code. For that you need System.Data.SQLitenamespace which will give you methods as well as Adapters and connections stuff to do so.

不幸的是,SQlite 文件中的密码只能从代码中添加、删除或更改。为此,您需要System.Data.SQLite命名空间,它会为您提供方法以及适配器和连接的东西来这样做。

回答by Pilgerstorfer Franz

Found in this foruman post indicating that ..

在这个论坛上发现一个帖子表明..

Standard SQLite3 API doesn't offer any form of protection and relies only on underlying OS privileges mecanism (if any) for "security". If you have an existing SQLite-style database which uses a specific API to gain access, then you should use this particular (non-standard) API.

Standard SQLite3 API doesn't offer any form of protection and relies only on underlying OS privileges mecanism (if any) for "security". If you have an existing SQLite-style database which uses a specific API to gain access, then you should use this particular (non-standard) API.

If you can/want to use some kind of extension for SQLite you can also try SQLite Encryption Extension (SEE)or SQLite Crypt

如果您可以/想要为 SQLite 使用某种扩展,您还可以尝试SQLite 加密扩展 (SEE)SQLite Crypt

But you can change/set a password for your database using SQLite.Dataas shown in this article.

但是您可以使用 SQLite.Data更改/设置数据库的密码,如本文所示。

回答by KF2

You can use the built-in encryption of the sq-lite.net provider (System.Data.SQLite). try this:

您可以使用sq-lite.net 提供程序 (System.Data.SQLite)的内置加密。尝试这个:

http://sqlite.phxsoftware.com/forums/t/130.aspxenter link description here

http://sqlite.phxsoftware.com/forums/t/130.aspx在此处输入链接描述

Or use:

或使用:

SQLiteCrypt API

SQLiteCrypt API

回答by Volkan Akku?

Try sqlitestudio.plas editor.
For Database Type, choose System.Data.SQLitewhile connecting.

尝试sqlitestudio.pl作为编辑器。
对于数据库类型,System.Data.SQLite在连接时选择。