3

I have a C# solution that uses System.Security to decrypt the password to a TFS server. The security routines are kept in a separate project within the solution. There are two other projects in the solution that use the module to decrypt this information.

It's using DPAPI and LocalMachineKey encryption. The two projects that get deployed from the solution are a Windows Service .exe and a .dll.

Everything's been working fine, except recently I had to test a new deploy of one of the projects (a TFS Work Item Event Handler) that uses the decryption module. I built the project on my machine, and deployed the dll to the test TFS server. I promptly began to get this error:

System.Security.Cryptography.CryptographicException: Key not valid for use in specified state.

   at System.Security.Cryptography.ProtectedData.Unprotect(Byte[] encryptedData, Byte[] optionalEntropy, DataProtectionScope scope)

Now, what's driving me absolutely crazy is that the other project (a Windows service) that uses the exact same module continues to work just fine. The passwords are the same, the config files haven't changed, but one application works and the other one...doesn't.

Can anyone point me in a direction to see what happened? Building the project on the test server doesn't seem to help, neither does reencrypting the password on the test machine to make sure it's using the right key. I've been tearing my hair out for two days now--this is a really minor change, but I can't deploy it until I can at least test it, and I don't want this problem to happen on the prod machine.

4

1 回答 1

0

删除文件夹 HKEY_CURRENT_USER\Software\Microsoft\VSCommon\12.0\ClientServices\TokenStorage

重新启动 Visual Studio

它应该再次工作。

http://davestechsolutions.blogspot.com.au/2015/11/key-not-valid-for-use-in-specified.html

于 2017-07-10T06:01:51.753 回答