当前位置:首页 » 密码管理 » 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#加密数据库 配置文件,该怎么弄

如果写在配置文件中,维护人员可以直接修改配置文件进行维护,而不需要将你的源程序修改、重新编译。

热点内容
主播网站源码 发布:2025-05-15 02:50:56 浏览:167
中文编程语言有哪些 发布:2025-05-15 02:48:59 浏览:535
配置中心应急流程有哪些 发布:2025-05-15 02:37:31 浏览:669
php宏定义 发布:2025-05-15 02:32:54 浏览:270
咸鱼支付密码哪里改 发布:2025-05-15 02:32:53 浏览:520
存储机箱 发布:2025-05-15 02:31:31 浏览:836
编程很累吗 发布:2025-05-15 02:29:25 浏览:552
疫情期间访问国外网络 发布:2025-05-15 02:24:24 浏览:247
我的世界网易版游戏服务器 发布:2025-05-15 02:23:46 浏览:221
全球编程网站 发布:2025-05-15 02:22:55 浏览:334