本文介绍了ProtectedData.Unprotect(DPAPI)密码更改后停止工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我对数据进行加密,并将其写入这样的文件:

Suppose I encrypt data and write it to a file like this:

byte[] encrypted =
    ProtectedData.Protect(plain, null, DataProtectionScope.CurrentUser);
File.WriteAllBytes(filename, encrypted);



解密是简单的:

Decrypting is as straightforward:

byte[] encrypted = File.ReadAllBytes(filename);
byte[] decrypted =
    ProtectedData.Unprotect(encrypted, null, DataProtectionScope.CurrentUser);

现在,当我改变调用之间我的Windows密码来保护和撤消,撤消会抛出异常。我确实想加密的数据链接到我的用户帐户,但我也希望它生存的密码更改。

Now when I change my windows password between the calls to Protect and Unprotect, Unprotect will throw an exception. I do want the encrypted data to be linked to my user account, but I also want it to survive password changes.

我想我有过到Windows到手的数据而不是把它写我自己的文件,这样Windows可以在更改密码重新加密。我只是找不到,告诉我如何的文档。有谁知道?

I guess I have to hand the data over to Windows rather than writing it to my own file, so that Windows can re-encrypt it on password changes. I just can't find the documentation that tells me how. Does anyone know?

推荐答案

如何的你更改密码?使用正常的程序,并指定旧密码应与 ProtectedData 工作,而设置在计算机管理不会。

How do you change the password? Using the normal procedure and specifying the old password should work with ProtectedData, while setting a new password under computer management wouldn't.

这篇关于ProtectedData.Unprotect(DPAPI)密码更改后停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 03:14