【发布时间】:2011-06-12 22:54:08
【问题描述】:
假设我加密数据并将其写入这样的文件:
byte[] encrypted =
ProtectedData.Protect(plain, null, DataProtectionScope.CurrentUser);
File.WriteAllBytes(filename, encrypted);
解密同样简单:
byte[] encrypted = File.ReadAllBytes(filename);
byte[] decrypted =
ProtectedData.Unprotect(encrypted, null, DataProtectionScope.CurrentUser);
现在,当我在调用 Protect 和 Unprotect 之间更改我的 Windows 密码时,Unprotect 将引发异常。我确实希望将加密数据链接到我的用户帐户,但我也希望它能够在密码更改后继续存在。
我想我必须将数据交给 Windows,而不是将其写入我自己的文件,以便 Windows 可以在密码更改时重新加密它。我只是找不到告诉我如何操作的文档。有人知道吗?
【问题讨论】:
标签: c#