- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的应用程序中,我需要加密各种设置和密码。到目前为止,我一直在使用 RijndaelManaged 类等进行此操作,如下所示:
/// <summary>
/// Encrypts the string defined by parameter "data" and returns the encrypted data as string
/// </summary>
/// <param name="data">Data to be encrypted</param>
/// <returns>The encrypted data</returns>
public static string Encrypt(string data)
{
if (data == "")
return "";
byte[] bytes = Encoding.ASCII.GetBytes(initVector);
byte[] rgbSalt = Encoding.ASCII.GetBytes(saltValue);
byte[] buffer = Encoding.UTF8.GetBytes(data);
byte[] rgbKey = new PasswordDeriveBytes(passPhrase, rgbSalt, hashAlgorithm, passwordIterations).GetBytes(keySize / 8);
RijndaelManaged managed = new RijndaelManaged();
managed.Mode = CipherMode.CBC;
ICryptoTransform transform = managed.CreateEncryptor(rgbKey, bytes);
MemoryStream memStream = new MemoryStream();
CryptoStream cryStream = new CryptoStream(memStream, transform, CryptoStreamMode.Write);
cryStream.Write(buffer, 0, buffer.Length);
cryStream.FlushFinalBlock();
byte[] inArray = memStream.ToArray();
memStream.Close();
cryStream.Close();
return Convert.ToBase64String(inArray);
}
通常的问题是我需要将密码(和盐值)存储在某处。为了以连续的方式存储密码,我遇到了 DPAPI Protect() 和 Unprotect() 类,如下所示:
/// <summary>
/// Use Windows' "Data Protection API" to encrypt the string defined by parameter "clearText".
/// To decrypt, use the method "Unprotect"
/// http://www.thomaslevesque.com/2013/05/21/an-easy-and-secure-way-to-store-a-password-using-data-protection-api/
/// </summary>
/// <param name="clearText"></param>
/// <param name="optionalEntropy"></param>
/// <param name="scope"></param>
/// <returns></returns>
public static string Protect(string clearText, string optionalEntropy = null, DataProtectionScope scope = DataProtectionScope.CurrentUser)
{
if (clearText == null)
throw new ArgumentNullException("The parameter \"clearText\" was empty");
byte[] clearBytes = Encoding.UTF8.GetBytes(clearText);
byte[] entropyBytes = string.IsNullOrEmpty(optionalEntropy) ? null : Encoding.UTF8.GetBytes(optionalEntropy);
byte[] encryptedBytes = ProtectedData.Protect(clearBytes, entropyBytes, scope);
return Convert.ToBase64String(encryptedBytes);
}
我的问题如下:使用 DPAPI,我现在可以以安全的方式存储我的加密方法的密码,但为什么我不应该直接使用 DPAPI 来加密我的所有设置?这是否会用大量数据填充 DPAPI,而它并不适合?
我的想法不是执行以下操作:
string setting1 = ”mySettingValue1”;
StoreSettingSomewhere(Encrypt(setting1));
我可以做以下事情:
string setting1 = ”mySettingValue1”;
StoreSettingSomewhere(Protect(setting1, bla bla bla));
我知道在使用 DPAPI 时我必须在同一台机器上(或使用同一用户)解密,但这对我来说不是问题。
感谢任何帮助!
最佳答案
Data Protection API 返回一个不透明的 blob,它是您想要加密的内容的加密(加盐和散列)结果。
您不能“填满” DP API - 您只能“填满”自己(因为 blob 有点大;但它们确实在内部包含了所有需要的东西稍后验证加密数据)。
Data Protection API 的缺点是您必须以用户身份登录;并且您不能在用户之间共享设置(除非您使用了计算机范围)。
关于c# - 为什么不使用 DPAPI 加密所有设置而不是只加密主密码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34651788/
我们有一个 WPF 应用程序,允许用户下载加密内容,并且我们希望提供离线解密该内容的功能。我的想法是下载 key 并使用 DPAPI 存储它们,但我在使用熵参数时遇到了问题。 是否有任何方法可以生成熵
你们中有人知道 Data Protection API for WP7 中使用的是什么加密算法吗? ? 我已经阅读了一些 MSDN 和 Wikipedia关于此的文章,但其中大部分都集中在 Windo
我正在 Windows 8 上开发一个 c# .net 3.5 应用程序。 我需要使用 DPAPI 加密数据。它在我的所有机器上工作正常,除了一台机器出现以下异常:System.Security.Cr
我正在使用 Windows DPAPI 为我加密一些敏感数据。密码存储在注册表中。这一切都很好,但我想知道是否有人可以澄清我对 .NET 中(可选)提供给 ProtectedData.Protect(
在我的应用程序中,我需要加密各种设置和密码。到目前为止,我一直在使用 RijndaelManaged 类等进行此操作,如下所示: /// /// Encrypts the string define
我不知道为什么会出现以下错误,“必须声明一个主体,因为它没有标记为抽象、外部或部分”。我实际上遵循以下站点中的指南'http://www.overclock.net/t/1293731/windows
我目前正在尝试了解如何最好地在 .NET 4.0 C# 环境中实现签名/验证。 我的要求是能够作为一个“用户”在我的系统中签署数据,在稍后的某个时候,该数据需要由消费者验证。 为了实现这一点,我正在尝
我在 C++ 中使用 DPAPI 来加密我需要存储在文件中的一些数据。问题是我需要从 C# 读取该文件,所以我需要能够: C++ 加密,C++ 解密(运行良好) C# 加密,C# 解密(运行良好) C
我正在使用 DPAPI 来存储 XML 数据。 CryptProtectData 之后的数据存储在一个文件中。在我的一个用例中,需要在任何用户登录到工作站之前解密此数据。因为,我不能在这里使用用户特定
所以我正在尝试使用 DPAPI 存储对称 key 。一切都很好,但是如何处理熵呢?这回答了问题 here确实没有提供足够的洞察力。这似乎是一个湿滑的斜坡——我可以使用机器商店来存储熵,但是是什么阻止了
我正在尝试找到在 Ubuntu Server 20.04 上存储 secret (供我的应用程序使用)的解决方案。我过去曾使用 Windows 的 DPAPI 来存储 secret ,使用访问 API
有没有比 Windows DPAPI 更安全的方式来保护和存储密码? 我的程序需要存储一个 secret (类似于凭据)以在 Windows 上进行自动登录,并且这个 secret 必须与其他用户帐户
假设有人可以访问我的所有硬盘,我猜弱点就是我的 Windows 密码。在不知道/无法检索的情况下,数据应该非常安全,不是吗? 我特地询问是因为 EFS entry在维基百科中指出 In Windows
我目前正在编写一个 c# mvc web 应用程序,其中从用户那里获取密码并将其存储在数据库 - sql server 中。我需要一种散列密码的方法。 建议使用数据保护 API (DPAPI)。我不熟
假设我加密数据并将其写入如下文件: byte[] encrypted = ProtectedData.Protect(plain, null, DataProtectionScope.Curr
有没有办法通过 Python 在 Windows XP 上使用 DPAPI(数据保护应用程序编程接口(interface))? 如果有可以做到的模块,我宁愿使用现有的模块。不幸的是,我无法通过 Goo
我们即将使用 DPAPI 来加密 ASP.NET 网络配置文件中的连接字符串。但是我对我们的网络集群(场)使用 RSA 还是 DPAPI 感到困惑。以下 MSDN 链接清楚地表明,如果我们想在网络场上
我正在考虑使用 Windows 的数据保护 API (DPAPI) 来加密一些数据。我的一个要求是在加密值时使用动态盐。 我通过测试注意到,如果我多次加密同一个字符串,我会得到不同的结果。这是使用相同
我正在使用 DPAPI(Data Protector API)来保护和取消保护数据。我正在从文件中读取数据。 C:\Users\nandkishore.sharma\AppData\Local\Goo
我关于 VBA 的初学者系列问题中的另一个。 我正在用 VBA 编写 Excel 插件,插件使用本地配置文件。 该文件需要包含远程服务的密码。 显然,将此密码存储为明文并不理想。但我正在寻找一种可以编
我是一名优秀的程序员,十分优秀!