web.config链接字符串加密记录 Jimmy

//这个就是解密ConnString,用解密后的串连接数据库就行啦

这里需要引入一个加密的dll

DesEncrypt.dll
dbHelper.ConnectionString = DecryptPassword(System.Configuration.ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString);

private static string DecryptPassword(string conn)
{

int pos= conn.IndexOf("Password=");
if (pos<=0) return conn; //没有找到密码原字符串返回
pos += 9;//加上Password=自身长度
int len=conn.IndexOf(';',pos);
if (len<=0)
len=conn.Length-pos;
else
len=len-pos;
string pass = conn.Substring(pos, len);
return conn.Replace(pass,DesEncrypt.DesEncrypt.Decrypt(pass));

}
原文地址:https://www.cnblogs.com/DemoLee/p/2515105.html