對weg.config中的敏感配置信息进行加密

习惯了将数据库连接字段直接写在web.config中,这样虽然方便,但是明文的数据库用户名和密码让人看着还是很反感!
想了许多方法 ,最后还是用了最方便、快捷的----aspnet_regiis.exe 来实现。

首先,打开VS2008的命令提示工具,输入:
C:\Windows\Microsoft.NET\Framework\v2.0.50727>aspnet_regiis.exe -pef "connectionStrings"D:\PersonalProjects\JQueryAndSql
(注意,只要输入到路径,不需要输入 web.config)


现在来看看加密后的connectionStrings节点:

<connectionStrings configProtectionProvider="RsaProtectedConfigurationProvider">
<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>d/+HLVqH82suUhGft/bL7t5Khzh0zD2pJWz7AYyUXKs4CpSrpMwEYlqpg1NI0phsT+CBan+w+zTTyT257eJL5XQbyeI2MpsGZLckR7ewXKgiF1WTwBC4O071N2C4OhH8GZrjJ2/rF43YCSr2o5b7H0Vj4exymDM2aaaUqI2A2lk=</CipherValue>
</CipherData>
</EncryptedKey>
</KeyInfo>
<CipherData>
<CipherValue>Q3Ew0n71wqEcu13RzArEDZCAwVug+84KAuzk0OU3PfkGn1c6duLn6m+IfmKrpqjZLl1PQnfOCShBF1sRbFUeTJ96stO/OPgBm5EfN8KF86h8X/OeAmVF5v1xlmzJjpiSd5qHnleLxpS2f7MruZImZPX4x9rbzb5FeHvWW+cgcVg=</CipherValue>
</CipherData>
</EncryptedData>
</connectionStrings>

当然也可以解密的,命令如下:
C:\Windows\Microsoft.NET\Framework\v2.0.50727>aspnet_regiis.exe -pdf "connectionStrings"D:\PersonalProjects\JQueryAndSql

看看解密后的代码:
<connectionStrings>
<add name="SQLCONN" connectionString="database=pubs;uid=sa;pwd=sa" />
</connectionStrings>





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值