在App.config中加密密码 [英] Encrypt password in App.config

查看:723
本文介绍了在App.config中加密密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在连接字符串中的密码进行加密。当我做一个连接到DB连接字符串是公开存储在App.config中,我需要找到一种方法,只保留密码加密。

I want to encrypt the password in connection string. When I make a connection to DB the connection string is openly stored in App.config and I need to find a way to keep only password encrypted.

推荐答案

可以说,这是你的连接字符串:

Lets say this is your connection string:

<connectionStrings>
    <add name="cs" connectionString="Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=XXSDFASFDKSFJDKLJFDWERIODFSDFHSDJHKJNFJKSD;"/>
</connectionStrings>

然后,你可以做这样的事情:

Then you can do something like this:

string myCs = System.Configuration.ConfigurationManager.ConnectionStrings["cs"].ConnectionString;

System.Data.SqlClient.SqlConnectionStringBuilder csb = new System.Data.SqlClient.SqlConnectionStringBuilder(myCs);
csb.Password = EncDecHelper.Decrypt(csb.Password);
myCs = csb.ToString();

您可以写 EncDecHelper.Decrypt 用样品从这里:的的加密/解密字符串在.NET

You can write EncDecHelper.Decrypt by using samples from here: Encrypt/Decrypt string in .NET

这篇关于在App.config中加密密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆