當前位置:首頁 » 密碼管理 » winform加密配置文件

winform加密配置文件

發布時間: 2022-04-22 08:58:28

❶ winform程序如何加密配置文件

下載個動軟,裡面有針對config文件加密的工具。

❷ c#怎麼加密配置文件

我的項目是這樣做的下面是App.config文件的內容,雖然是明文,但我想用戶應該是看不懂的<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="sqlcn" value="cemqpbije=exq;bt=ejv;bubE_uojsQfepdsbC=ftbcbube;4.1.972.302=sfwsft"/>
</appSettings>
</configuration> 其實value的值應是:server=192.168.0.3;database=BarcodePrint_Data;uid=sa;pwd=dihaopldb 僅僅是自己寫了一個演算法。我這演算法的思路是:將字元串反轉,再將ASCII加一個值(加密)反轉加密的字元串,再將ASCII減一個值(解密) 思路供你參考,其實有很多種方式,樓主可以自己去思考,自己去寫一個試試

❸ C# 怎麼保存WinForm應用程序的配置

供參考:
1.自定義一個
配置文件
(.config/.txt),比如:在BIN目錄下生成一個setting.config,通過winform界面把配置參數全部保存到這裡面來。
2.保存到app.config中,可以把一些配置參數保存到app.config,這樣在窗體編譯的時候,app.config
會自動生成到BIN目錄下。
3.保存到資料庫指定的表,比如:D_DataBase/T_Setting表,可以通過winform界面把參數全部保存到資料庫指定的表中。
4.保存到注冊表中。

❹ C# winform 的配置文件用什麼保存好,txt,ini.還是xml.

都可以,看你自己選擇了
txt需要自定義格式
xml可以用XmlDocument操作
ini要通過DllImport("kernel32")來引入外部函數操作

❺ 如何為配置文件加密

在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,都只能在進行加密的計算機上對配置文件進行解密。

❻ c#資料庫連接加密

我來回答吧: 不懂可以Hi,我一般都是這么做的

先給你個加密和解密類
告訴你個加密 解密類。
using System;
using System.IO;
using System.Security.Cryptography;

namespace CryptInfoNameSpace
{
class CryptInfo
{
//加密
public static string Encrypt(string text)
{
Rijndael crypt=Rijndael.Create();
byte[] key=new byte[32]{0XA6,0X7D,0XE1,0X3F,0X35,0X0E,0XE1,0XA9,0X83,0XA5,0X62,0XAA,0X7A,0XAE,0X79,0X98,
0XA7,0X33,0X49,0XFF,0XE6,0XAE,0XBF,0X8D,0X8D,0X20,0X8A,0X49,0X31,0X3A,0X12,0X40};
byte[] iv=new byte[16]{0XF8,0X8B,0X01,0XFB,0X08,0X85,0X9A,0XA4,0XBE,0X45,0X28,0X56,0X03,0X42,0XF6,0X19};

crypt.Key=key;
crypt.IV=iv;

MemoryStream ms=new MemoryStream();
ICryptoTransform transformEncode=new ToBase64Transform();
//Base64編碼
CryptoStream csEncode=new CryptoStream(ms,transformEncode,CryptoStreamMode.Write);

CryptoStream csEncrypt=new CryptoStream(csEncode,crypt.CreateEncryptor(),CryptoStreamMode.Write);

System.Text.UTF8Encoding enc=new System.Text.UTF8Encoding();
byte[] rawData=enc.GetBytes(text);

csEncrypt.Write(rawData,0,rawData.Length);
csEncrypt.FlushFinalBlock();

byte[] encryptedData=new byte[ms.Length];
ms.Position=0;
ms.Read(encryptedData,0,(int)ms.Length);
return enc.GetString(encryptedData);
}
//解密,加密解密中的 byte[] key,byte[] iv可以自行修改,加密解密的 數組值一定一致,否則無法對應加密 解密。
public static string Decrypt(string text)
{
Rijndael crypt=Rijndael.Create();
byte[] key=new byte[32]{0XA6,0X7D,0XE1,0X3F,0X35,0X0E,0XE1,0XA9,0X83,0XA5,0X62,0XAA,0X7A,0XAE,0X79,0X98,
0XA7,0X33,0X49,0XFF,0XE6,0XAE,0XBF,0X8D,0X8D,0X20,0X8A,0X49,0X31,0X3A,0X12,0X40};
byte[] iv=new byte[16]{0XF8,0X8B,0X01,0XFB,0X08,0X85,0X9A,0XA4,0XBE,0X45,0X28,0X56,0X03,0X42,0XF6,0X19};

crypt.Key=key;
crypt.IV=iv;

MemoryStream ms=new MemoryStream();

CryptoStream csDecrypt=new CryptoStream(ms,crypt.CreateDecryptor(),CryptoStreamMode.Write);

ICryptoTransform transformDecode=new FromBase64Transform();
CryptoStream csDecode=new CryptoStream(csDecrypt,transformDecode,CryptoStreamMode.Write);

System.Text.UTF8Encoding enc=new System.Text.UTF8Encoding();
byte[] rawData=enc.GetBytes(text);
csDecode.Write(rawData,0,rawData.Length);
csDecode.FlushFinalBlock();

byte[] decryptedData=new byte[ms.Length];
ms.Position=0;
ms.Read(decryptedData,0,(int)ms.Length);
return(enc.GetString(decryptedData));
}
}
}

在項目中 引用該類,
下面個思路:

把數據連接字元串 ,經過CryptInfoNameSpace.CryptInfo.Encrypt(string text)加密後 ,寫入配置文件inf 或者 配置文件txt文件。
當執行Main函數時,讀取配置文件,(如果配置文件不存在,或者讀取錯誤, 重新加密的資料庫連接字元串加密後寫入配置文件)。然後通過函數 CryptInfoNameSpace.CryptInfo.Decrypt(string text)方法解密成原文連接字元串,並傳遞給其他類使用。即可。

❼ C#自定義應用程序配置文件 節加密怎麼實現

如上所說,寫進去時加密就可以,讀取時再解密, 如下:
///<summary>
///這是添加配置節時
///在*.exe.config文件中appSettings配置節增加一對鍵、值對
///</summary>
///<param name="newKey">配置節鍵</param>
///<param name="newValue">配置節值</param>
public static void UpdateAppConfig(string newKey, string newValue)
{
bool isModified = false;
foreach (string key in ConfigurationManager.AppSettings)
{
if (key == newKey)
{
isModified = true;
}
}
// Open App.Config of executable
Configuration config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
// You need to remove the old settings object before you can replace it
if (isModified)
{
config.AppSettings.Settings.Remove(newKey);
}
// Add an Application Setting.
config.AppSettings.Settings.Add(newKey, StringEncry.EncodeBase64(newValue));
// Save the changes in App.config file.
config.Save(ConfigurationSaveMode.Modified);
// Force a reload of a changed section.
ConfigurationManager.RefreshSection("appSettings");
}
///<summary>
///讀取配置節時
///返回*.exe.config文件中appSettings配置節的value項
///</summary>
///<param name="strKey">配置節鍵</param>
///<returns></returns>
public static string GetAppConfig(string strKey)
{
foreach (string key in ConfigurationManager.AppSettings)
{
if (key == strKey)
{
return StringEncry.DecodeBase64(ConfigurationManager.AppSettings[strKey]);
}
}
return "";
}

❽ C#關於文件加密!

本地配置文件可以以密文的形式存放,寫一個配置文件讀寫類,加解密的密鑰寫在類裡面就可以了。先讀取配置文件密文,解密,對配置文件做對應操作,更新配置文件之後在加密寫會本地就行了。另外AES加密演算法用的會多一些,安全性,效率都優於DES..net中也封裝了這些加密演算法的類,可以直接用。

❾ c#加密資料庫 配置文件,該怎麼弄

如果寫在配置文件中,維護人員可以直接修改配置文件進行維護,而不需要將你的源程序修改、重新編譯。

熱點內容
編譯器怎麼處理c變長數組 發布:2025-05-14 23:31:46 瀏覽:661
存摺每天可以輸錯多少次密碼 發布:2025-05-14 23:22:06 瀏覽:907
安卓手機怎麼找微信隱藏對話 發布:2025-05-14 23:07:47 瀏覽:336
怎麼查看泰拉伺服器ip 發布:2025-05-14 23:03:29 瀏覽:72
c語言學生成績查詢系統 發布:2025-05-14 22:58:30 瀏覽:4
怎麼進別人的伺服器 發布:2025-05-14 22:45:55 瀏覽:772
用編程寫音樂 發布:2025-05-14 22:45:08 瀏覽:782
如何識別電腦的網路配置 發布:2025-05-14 22:38:46 瀏覽:847
pipforpython3 發布:2025-05-14 22:38:34 瀏覽:350
如何把迷你世界的伺服器搞崩 發布:2025-05-14 22:37:15 瀏覽:94