System.Security.Cryptography.UnProtect is not working when the windows user password is changed

G R BABU 1 Reputation point
2022-06-05T13:57:03.113+00:00

I am using System.Security.Cryptography.Protect and UnProtect methods to encrypt and decrypt the data with DataProtectionScope as CurrentUser. All works fine until the user changes the windows user Password(due to group policy enforced for password change). It stopped working with an error "Key not valid for use in specified state"

here is an example I have used in the code.

encrypted = ProtectedData.Protect(data, null, DataProtectionScope.CurrentUser);

decrypted = ProtectedData.Unprotect(encryptedData, null, DataProtectionScope.CurrentUser);

Appreciate your help Thanks in Advance.

Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
{count} votes

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.