ProtectedData.Unprotect method throws CryptographicException when different OS is installed on same machine

81 Views Asked by At

Our application is installed on a client location. The application uses ProtectedData.Protect method to protect a key on the client machine and saves the output to a file. Following is the code :

ProtectedData.Protect(sampleHashKey, entropy, DataProtectionScope.LocalMachine); where Entropy is a byte array.

The client has updated the Operating system on that machine to Windows 2016 Server and backed up the hash key file before doing so and reinstalled our software which created a new hash key file. The client replaced the new hash key file with the backed up file. When the software tried to read the file, using the unprotect mechanism with the following code : ProtectedData.Unprotect(sampleHashKey, entropy, DataProtectionScope.LocalMachine); a CryptographicException was thrown with the error : Key not valid for use in specified state.

Why has this error occurred even if the file was created on the same machine with DataProtectionScope.Localmachine? Will it not work cross OS on the same machine? Could someone explain me the issue?

0

There are 0 best solutions below