MVC AntiForgeryToken的machineKey加密 [英] MVC AntiForgeryToken machinekey for encryption

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

问题描述

我才知道:在幕后,在MVC AntiForgeryToken属性使用加密将machineKey。如果你没有在web.config中指定的machineKey,系统会自动为您ASP.NET生成的。

如果ASP.NET应用程序重新启动(例如做一个IISRESET),浏览器cookie中的AntiForgeryToken仍将使用旧机键,因此它以上述错误崩溃被加密。

我关心的是

在写web.config中的计算机密钥我想知道我应该寻找机键复制&安培;粘贴在web.config中。当我们在本地PC正在测试那么我们可以复制和放大器;粘贴在web.config中机按键,但是当我们将举办我们的网站,godady或ORCSWEB在共享的环境那么这些公司可能不会给我们的在那里的网站将被托管的PC机键。所以我需要知道如何处理这种情况。谢谢

修改

 <结构>
    <&的System.Web GT;
        <的machineKey
            validationKey=\"21F090935F6E49C2C797F69BBAAD8402ABD2EE0B667A8B44EA7DD4374267A75D7AD972A119482D15A4127461DB1DC347C1A63AE5F1CCFAACFF1B72A7F0A281B\"
            decryptionKey =ABAA84D7EC4BB56D75D217CECFFB9628809BDB8BF91CFCD64568A145BE59719F
            验证=SHA1
            解密=AES
        />

如何获得或产生的validationKey和放大器; decryptionKey分开?任何想法?


解决方案

  

如果ASP.NET应用程序重新启动(例如做一个IISRESET)时,
  的浏览器cookie内AntiForgeryToken仍会被加密
  与旧机键???


我不认为有IISRESET机关键变化。

您可以生成计算机密钥(验证和解密密钥)和自己在web.config中指定。相同的密钥将在其中进行例如加密所有情况下使用验证票,AF令牌。

一个很好的介绍链接

更新:

如何生成计算机密钥?

有不同的方式,这 MSDN博客建议使用IIS看起来更安全的把我当成正在使用微软的工具。然而,似乎此功能只支持到IIS 7上我的盒子IIS 8.5我并不​​觉得。我在IIS 7.5,它不是present检查有两种。然而,我发现它在IIS 6.1上一个同事框。

第二个选择是使用自定义密钥生成器

一个。 计算机密钥生成(在线)

乙。 ASP.NET的machineKey发电机(工具可以修改)

i came to know : Under the covers, the MVC AntiForgeryToken attribute uses the machinekey for encryption. If you don't specify a machinekey in the web.config , one is automatically generated for you by ASP.NET.

If the ASP.NET application is restarted (e.g. do an iisreset), the AntiForgeryToken within the browser cookie will still be encrypted with an old machine key, hence why it crashes with the above error.

My concern is

before write the machine key in web.config i like to know where i should look for the machine key to copy & paste in web.config. when we are testing in local pc then we can copy & paste the machine key in web.config but when we will host our site in godady or ORCSWEB in shared environment then those company may not give machine key of the pc where our site will be hosted. so i need to know how to handle this situation. thanks

EDIT

<configuration>
    <system.web>
        <machineKey  
            validationKey="21F090935F6E49C2C797F69BBAAD8402ABD2EE0B667A8B44EA7DD4374267A75D7AD972A119482D15A4127461DB1DC347C1A63AE5F1CCFAACFF1B72A7F0A281B"           
            decryptionKey="ABAA84D7EC4BB56D75D217CECFFB9628809BDB8BF91CFCD64568A145BE59719F"
            validation="SHA1"
            decryption="AES"
        />

how to get or generate validationKey & decryptionKey separately ? any idea?

解决方案

If the ASP.NET application is restarted (e.g. do an iisreset), the AntiForgeryToken within the browser cookie will still be encrypted with an old machine key???

I don't think machine key changes with iisreset.

You can generate machine key (validation and decryption key) yourself and specify it in web.config. The same key will be used in all cases where encryption is performed e.g. Auth tickets, AF Token.

A good introduction link.

UPDATE:

How to generate machine key?

There are various way, this msdn blog suggest using IIS which looks more secure to me as Microsoft tool being used. However, it seems this feature is only supported until IIS 7. I don't find it on my box IIS 8.5. I checked on IIS 7.5 and its not present there either. However, I found it in IIS 6.1 on a coworker box.

Second option is to use custom key generators

a. Machine Key Generator (online)

b. ASP.NET machineKey Generator (tool you can modify)

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

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