C# 在 .NET 中以编程方式加密配置文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21965/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Programmatically encrypting a config-file in .NET
提问by Seb Nilsson
Could somebody please do a rundown of how to programmatically encrypt a config-file in .NET, preferably in C#.
有人可以简要介绍一下如何以编程方式加密 .NET 中的配置文件,最好是在 C# 中。
What I would like to do is do some kind of check on an application's startup to see if a section is unprotected, and if it is, then encrypt it. This for both settings and connection-strings.
我想做的是对应用程序的启动进行某种检查,以查看某个部分是否不受保护,如果是,则对其进行加密。这适用于设置和连接字符串。
Also if anyone could list the types of encryption-providers and what is the difference between them.
此外,如果有人可以列出加密提供程序的类型以及它们之间的区别。
I don't know if the code for doing this in a normal WinForms-application is transparent to doing this in ASP.NET.
我不知道在普通 WinForms 应用程序中执行此操作的代码对于在 ASP.NET 中执行此操作是否透明。
采纳答案by Seb Nilsson
To summarize the answers and what I've found so far, here are some good links to answer this question:
为了总结答案以及我到目前为止的发现,这里有一些很好的链接来回答这个问题:
- Encrypting Configuration Information in ASP.NET 2.0 Applications - 4GuysFromRolla.com
- How To: Encrypt Configuration Sections in ASP.NET 2.0 Using DPAPI - MSDN
Please feel free to complement with other links, maybe some to WinForms- or WPF-applications.
请随意补充其他链接,也许是 WinForms 或 WPF 应用程序的一些链接。
回答by Espo
There is a good article from 4 guys about Encrypting Configuration Information in ASP.NET 2.0 Applications
有 4 个人写了一篇关于在 ASP.NET 2.0 应用程序中加密配置信息的好文章
Hope this helps
希望这可以帮助
回答by ArjanZuidhof
@TK: a hashing algo can only be 'guessed', not reverse engineered. One can only reconstruct the input to a hash value by completely guessing the input (apart from collisions, that is) This can be done by a rainbow crack for example (see an implementation of a rainbow cracker here)
@TK:散列算法只能“猜测”,不能逆向工程。人们只能通过完全猜测输入(除了冲突,即)将输入重建为哈希值,例如,这可以通过彩虹裂缝来完成(请参阅此处的彩虹裂缝实现)
I would say that a 3rd party encryption tool is not safer than the .NET framework encryption algorithms, these libraries just help you doing your job faster
我会说第 3 方加密工具并不比 .NET 框架加密算法更安全,这些库只是帮助您更快地完成工作
回答by DAC
I haven't used it myself, but the Microsoft Enterprise library has good encryption support that will possibly suit your needs:
我自己没有使用过,但 Microsoft Enterprise 库具有良好的加密支持,可能会满足您的需求:
回答by Aviator007
The solution at below site working fine for me.
以下站点的解决方案对我来说工作正常。
http://www.a2zmenu.com/Blogs/CSharp/How-to-encrypt-configuration-file.aspx
http://www.a2zmenu.com/Blogs/CSharp/How-to-encrypt-configuration-file.aspx