connectionstring加密
給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驗證方式)。
如果是在伺服器上,那你就不要讓程序直接庫,而是寫一個中間通訊程序。