当前位置:首页 » 密码管理 » connectionstring加密

connectionstring加密

发布时间: 2023-05-10 23:05:03

‘壹’ 怎样给sqlite数据库文件进行加密解密

给SQLite数据库加密解密的方法:
1、创建空的sqlite数据库。
//数据库名的后缀你可以直接指定,甚至没有后缀都可以
//方法一:创建一个空sqlite数据库,用IO的方式
FileStream fs = File.Create(“c:\\test.db“);
//方法二:用SQLiteConnection
SQLiteConnection.CreateFile(“c:\\test.db“);

创建的数据库是个0字节的文件。
2、创建加密的空sqlite数据库
//创建一个密码为password的空的sqlite数据库
SQLiteConnection.CreateFile(“c:\\test2.db“);
SQLiteConnection cnn = new SQLiteConnection(“Data Source=c:\\test2.db“);
SQLiteConnection cnn = new SQLiteConnection(“Data Source=D:\\test2.db“);
cnn.Open();
cnn.ChangePassword(“password“);

3、给未加密的数据库加密
SQLiteConnection cnn = new SQLiteConnection(“Data Source=c:\\test.db“);
cnn.Open();
cnn.ChangePassword(“password“);

4、打开加密sqlite数据库
//方法一
SQLiteConnection cnn = new SQLiteConnection(“Data Source=c:\\test2.db“);
cnn.SetPassword(“password“);
cnn.Open();
//方法二
SQLiteConnectionStringBuilder builder = new SQLiteConnectionStringBuilder();
builder.DataSource = @”c:\test.db“;
builder.Password = @”password“;
SQLiteConnection cnn = new SQLiteConnection(builder.ConnectionString);
cnn .Open();

除了用上述方法给SQLite数据库加密以外,您还可以使用专业的文件加密软件将SQLite数据库加密。

超级加密 3000采用先进的加密算法,使你的文件和文件夹加密后,真正的达到超高的加密强度,让你的加密数据无懈可击。

超级加密3000使用起来,只要点击需要加密的文件的右键,即可轻松实现文件的加密。

解密只要双击已加密文件,输入密码即可轻松搞定。

‘贰’ 如何为配置文件加密

在web.config或app.config文件里我们经常会存储一些敏感信息,比如connectionStrings或者appSettings,比如像下面的文件。
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<connectionStrings>
<add name="MyNwConnectionString" connectionString="Server=myServerAddress;Database=myDataBase;User Id=myUsername; Password=myPassword;"/>
</connectionStrings>
<appSettings>
<add key="User" value="myUsername"/>
<add key="Password" value="myPassword"/>
</appSettings>
</configuration>
using System;
using System.Configuration;

namespace WebConfigEncryptTest
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string user = ConfigurationManager.AppSettings.Get("User");
string password = ConfigurationManager.AppSettings.Get("Password");
string connectionString = ConfigurationManager.ConnectionStrings["MyNwConnectionString"].ConnectionString;
}
}
}

(一)加密文件可以使用的Provider
.NET为我们提供了一个工具aspnet_regiis.exe来对web.config文件中的敏感信息进行加密(app.config文件可以先改名为web.config,加密后再改回app.config)。你可以使用两个provider中的一个来进行加密:
System.Configuration.:在System.Configuration.dll中,使用Windows DPAPI(Data Protection API)来进行加密,密钥存在Windows Local Security Authority(LSA)中。注意:当使用时,加密文件所使用的帐号需要与运行web application的帐号相同,否则web application无法解密加密的内容。
System.Configuration.:在System.Configuration.dll中,使用RSA算法来进行加密(RSA算法是非对称加密,参见《对称加密与非对称加密 》),公钥存放在config文件当中,只有加密的计算机有密钥。通常是默认的缺省provider。
(二)加密文件的命令
加密web.config文件可以使用:
aspnet_regiis -pef section web-app-physical-dir
Encrypt the configuration section. Optional arguments:
[-prov provider] Use this provider to encrypt.

比如运行下面的命令就会分别对connectionStrings和appSettings中的信息进行加密:

aspnet_regiis.exe -pef "connectionStrings" "C:\myweb\HelloService"
aspnet_regiis.exe -pef "appSettings" "C:\myweb\HelloService"

加密后的web.config文件变成:

<?xml version="1.0"?>
<configuration>
<system.web>
<compilation targetFramework="4.0" />
</system.web>
<connectionStrings configProtectionProvider="">
<EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element"
xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<KeyName>Rsa Key</KeyName>
</KeyInfo>
<CipherData>
<CipherValue>E2fO9C0TJVxImLYQZza+fCQdDbTpNh/kOKLRsK6zcFjkgtUCl6SnMViuu/2G1NVTxqXyEWYwyK6AiCZA+feeG/+f2EIimP7LJI+JRZVerI4MU6Ke3wxm2S/ATc73/W6eg9808f4//JB0kso0kGJ9i+==</CipherValue>
</CipherData>
</EncryptedKey>
</KeyInfo>
<CipherData>
<CipherValue>I1DWG11Iz/rq+NC9C/21B3Q22J9+//JW1oCvAGs5tHrZU5+vgvm0yCmSuCWZbXva+iv9J35EQqs58pq+hwVo1hg1dffpGCBykaXGl5VX3TIGc=</CipherValue>
</CipherData>
</EncryptedData>
</connectionStrings>
<appSettings configProtectionProvider="">
<EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element"
xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<KeyName>Rsa Key</KeyName>
</KeyInfo>
<CipherData>
<CipherValue>//SuBvV3D2kxhHaYGFaPuvYgsyOLf3+aYR3O/uh/+/iSANzAWoC+==</CipherValue>
</CipherData>
</EncryptedKey>
</KeyInfo>
<CipherData>
<CipherValue>5W2KhG/oETLUDptobcOM52x1qD/g9A0By/wcGXI+///w=</CipherValue>
</CipherData>
</EncryptedData>
</appSettings>
</configuration>

是默认的缺省provider,如果想使用,可以用-prov参数指明:

aspnet_regiis.exe -pef "connectionStrings" "C:\myweb\HelloService" -prov ""
aspnet_regiis.exe -pef "appSettings" "C:\myweb\HelloService" -prov ""

加密配置文件后,源程序不需要做任何改动。如果要修改或添加新的配置信息,需要先解密配置文件。不论使用哪种Provider,都只能在进行加密的计算机上对配置文件进行解密。

‘叁’ 如何解密下面的字符串 它是什么加密方式

解密为:
通过本工具可以快速检测网页的META标签,分析标题、关键词、描述等是否有利于搜索引擎收录

‘肆’ .net sqlconnection 连接字符串如何加密

没有决对的安全。
可以把连接串做成程序集的资源。

数据库是在客户端吗,那可以直接绕过你的程序,用数据库工具连上了(windows验证方式)。
如果是在服务器上,那你就不要让程序直接库,而是写一个中间通讯程序。

热点内容
编译原理设计文档是什么 发布:2025-02-10 09:41:58 浏览:283
sql分段统计 发布:2025-02-10 09:40:27 浏览:358
记账app源码 发布:2025-02-10 09:34:45 浏览:496
照片传到g6的存储卡 发布:2025-02-10 09:29:02 浏览:902
非加密公章 发布:2025-02-10 09:09:52 浏览:621
京东登录密码如何清除 发布:2025-02-10 09:07:41 浏览:690
dns服务器地址192 发布:2025-02-10 09:07:39 浏览:662
redis缓存实现 发布:2025-02-10 09:01:26 浏览:711
后台登录脚本 发布:2025-02-10 08:56:11 浏览:659
我的辣鸡账号和密码是多少 发布:2025-02-10 08:55:37 浏览:691