• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

加密web.config的方法分享

asp 搞代码 4年前 (2022-01-03) 25次浏览 已收录 0个评论

加密web.config的方法分享,需要的朋友可以参考一下

1、打开记事本,然后将下面的代码复制到一个新文件中。

代码如下:

<%
Response.Write(System.Security.Principal.WindowsIdentity.GetCurrent().Name);
%>

 保存 my.aspx 到你的web目录 ,运行一下窗体显示 “ NT AUTHORITY\NETWORK SERVICE ”。成功!

2、(关键一步)运行cmd,执行以下

   aspnet_regiis -pa “NetFrameworkConfigurationKey” “NT AUTHORITY\NETWORK SERVICE”

   说明:注册默认的 RsaProtectedConfigurationProvider 的RSA 密钥容器,
    NetFrameworkConfigurationKey 是 RsaProtectedConfigurationProvider 的默认provider。 成功!

3、现在,可以加密web.config ,运行:

   加密:aspnet_regiis -pe “connectionStrings” -app “/Myweb” 
       说明:”connectionStrings” 是要加密的节,”/Myweb”是的web目录      
   解密:aspnet_regiis -pd “connectionStrings” -app “/Myweb” 

   成功!    

4、这样就可以在程序里调用了(不用解密, 哈哈

):
    …
    string connstr= ConfigurationManager.ConnectionStrings[“myConnstr”].ConnectionString.ToString();
    …

 同样的,也可以用创建自己的RSA 密钥容器,如下:

  (1)、创建 “MyKeys” 密钥容器,运行:aspnet_regiis -pc “MyKeys” -exp
 (2)、在web.config里加入以下:
 

代码如下:
     
       
                       type=”System.Co来源gao*daima.com搞@代#码网nfiguration.RsaProtectedConfigurationProvider, System.Configuration, Version=2.0. 0.0,
                    Culture=neutral, PublicKeyToken=b03f5f7f11d0a3a,
                    processorArchitecture=MSIL”
              keyContainerName=”MyKeys”
              useMachineContainer=”true” />
       
     
    

        保存。

 (3)、授予帐户对计算机级别的 “MyKeys” RSA 密钥容器的访问权限,运行:

       aspnet_regiis -pa “MyKeys” “NT AUTHORITY\NETWORK SERVICE”

  (4)、现在,可以加密web.config ,运行:

     加密:aspnet_regiis -pe “connectionStrings” -app “/Myweb”-prov “MyProvider” 

             说明:”connectionStrings” 是要加密的节,”/Myweb”是的web目录,”MyProvider” 自己密钥容器

        解密:aspnet_regiis -pd “connectionStrings” -app “/Myweb”-prov “MyProvider”

以上就是加密web.config的方法分享的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:加密web.config的方法分享

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址