假设我加密数据并将其写入如下文件:
byte[] encrypted =
ProtectedData.Protect(plain, null, DataProtectionScope.CurrentUser);
File.WriteAllBytes(filename, encrypted);
Run Code Online (Sandbox Code Playgroud)
解密就像直截了当:
byte[] encrypted = File.ReadAllBytes(filename);
byte[] decrypted =
ProtectedData.Unprotect(encrypted, null, DataProtectionScope.CurrentUser);
Run Code Online (Sandbox Code Playgroud)
现在,当我在保护和取消保护的调用之间更改我的Windows密码时,Unprotect将抛出异常.我确实希望将加密数据链接到我的用户帐户,但我也希望它能够在密码更改后继续使用.
我想我必须交给Windows中的数据,而不是将其写入到我自己的文件,以便Windows可以在更改密码重新加密.我只是找不到告诉我如何的文档.有人知道吗?