tin*_*k01 2 .net c# encryption
我正在寻找一种安全的方法来加密和解密Visual Studio项目中的字符串(在C#中).我发现有原生的DES类,但它不够安全.你有什么建议吗?
更新: 那么,问题是:加密/解密字符串的最安全的方法是什么,没有太多的麻烦(也就是说必须安装外部工具等等.外部库虽然很好).在哪里放秘密"密钥"(正在编译代码中的值足够安全吗?).
更新#2 如果我使用类似此代码的内容将加密字符串保存在配置文件中:
using System.Security.Cryptography;
using System.Security;
byte[] encrypted = ProtectedData.Protect(StrToByteArray("my secret text"), null, DataProtectionScope.LocalMachine);
byte[] derypted = ProtectedData.Unprotect(encrypted , null, DataProtectionScope.LocalMachine);
Run Code Online (Sandbox Code Playgroud)
这足够安全吗?我想用"LocalMachine"参数而不是"User"参数,有人可以在.net中编写一个应用程序,将它放在机器上并执行它来解密加密的字符串.因此,如果我希望它更安全,我将不得不为每个用户配置不同的配置文件?我理解正确吗?
要回答第二个问题,不,将加密密钥存储在可执行文件中,甚至是模糊处理,根本不安全.它会保持随意窥探的眼睛,但不是那些有一个小时专门用于穿过你的反应源的人.
仔细考虑存储加密密钥的位置 - 看起来这将是你的弱点.是的,这是一个难以解决的问题.存储加密密钥的最安全方法不是 - 要求用户键入密码,或者需要外部硬件,如密钥卡.
如果要加密要在单台计算机上或单个域用户上读取的内容,请考虑使用Data Protection API(DPAPI).它需要加密密钥 - 它使用用户的Windows凭据作为密钥.
我在另一个答案中有更多细节:使用.Net持久存储加密数据
关于你的第二次编辑(DataProtectionScope.LocalMachine是否足够好?); 这篇MSDN博客文章总结得很好:
Setting a scope of DataProtectionScope.CurrentUser encrypts the data so that only the currently logged on user can decrypt it. Switching to DataProtectionScope.LocalMachine allows any process running on the current machine to decrypt the data. This could be useful in a server scenario, where there are no untrusted logins to the machine, but for a general purpose workstation using LocalMachine encryption is almost equivalent to using no encryption at all (since anybody logged in can get at the data).
| 归档时间: |
|
| 查看次数: |
2722 次 |
| 最近记录: |