简体   繁体   English

相当于MachineKey.Protect / Unprotect的非ASP.Net

[英]Non-ASP.Net equivalent of MachineKey.Protect/Unprotect

Is there a simple to use encrypt/decrypt method outside the System.Web.Security namespace that are as easy to use as MachineKey.Protect/MachineKey.Unprotect() ? System.Web.Security命名空间之外,是否有一种简单易用的加密/解密方法,它与MachineKey.Protect/MachineKey.Unprotect()一样容易使用?

Or does anyone know if you can set up this outside ASP.Net as my quick trial showed that it seemed to generate a new key or something in between app restarts meaning you couldn't decrypt anything between restarts of the app. 还是有人知道您是否可以在ASP.Net之外进行设置,因为我的快速试用显示它似乎在应用程序重新启动之间生成了新密钥或某些东西,这意味着您无法在应用程序重新启动之间解密任何内容。

I can roll my own using the appropriate classes, I was just wondering if they'd finally provided a simpler API? 我可以使用适当的类自己滚动,我只是想知道它们是否最终会提供更简单的API?

I was searching for this as well. 我也在寻找这个。 And after spent a few hours digging around, I found System.Security.Cryptography.ProtectedData . 经过数小时的挖掘,我找到了System.Security.Cryptography.ProtectedData The usage is very similar, just that you need to provide the scope. 用法非常相似,只是您需要提供范围。 And here's the best part: it's available from .NET 2.0. 这是最好的部分:可从.NET 2.0获得。

Hope this helps someone someday. 希望有一天能对某人有所帮助。

The MachineKey in asp.net is autogenerated every time it starts up. 每次启动时,都会自动生成asp.net中的MachineKey。 To get around this you can set the MachineKey explicitly. 为了解决这个问题,您可以显式设置MachineKey

Of course, if the process is running on the same machine as your potential hacker, it's all a bit pointless. 当然,如果该进程与您的潜在黑客在同一台计算机上运行,​​那么一切都毫无意义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM