C# 对App.config、Web.config的appSettings节点数据进行加密

appSettings加密原因,就是因为容易暴露服务器账号和密码,而且客户也不允许
使用ASP.NET提供的命令工具aspnet_regiis来创建加密命令;aspnet_regiis是提供了直接对配置文件加密的功能的;并且使用aspnet_regiis加密的配置节点在读取时不需要手动解密,.Net会自行解密并返回解密后的数据。

找到aspnet_regiis工具目录
示例:C:\Windows\Microsoft.NET\Framework\v4.xxxxx
打开cmd控制台,CD进入C:\Windows\Microsoft.NET\Framework\v4.xxxxx目录下

开始加密

aspnet_regiis.exe -pef connectionStrings "C:\MyAppFolder" -prov "DataProtectionConfigurationProvider"


这个命令将加密config文件中的connectionStrings节点,C:\MyAppFolder指你程序部署的绝对路径。

aspnet_regiis.exe -pef "appSettings" "C:\MyAppFolder" -prov "DataProtectionConfigurationProvider"


这个命令将会加密config文件中的appSettings节点,C:\MyAppFolder指你程序部署的绝对路径。

开始解密

aspnet_regiis.exe -pdf connectionStrings "C:\MyAppFolder"


这个命令将解密config中的已经加密的connectionStrings节点。

aspnet_regiis.exe -pdf "appSettings" "C:\MyAppFolder"


这个命令将会解密config文件中的appSettings节点。

其它


加密后

————————————————


                      

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值