CryptographicException: Key not valid for use in specified state



Hi

I'm using the RSACryptoServiceProvider to encrypt and decrypt passwords.
The key is stored as an XML string and I use the
RSACryptoServiceProvider.FromXmlString method to read it.

I've used the same class successfully in several applications over several
months. However, in the last week it has given me problems. I'm getting the
CryptographicException "Key not valid for use in specified state" when the
FromXmlString method runs.

Does anyone have any idea as to what causes this exception message?

The key that is stored as XML hasn't changed since the last time the
application worked. The problem appears to be related to the user account
the application is running under. The application can run as either a
Windows Forms app or a Windows service. It runs fine when I run it as a
Windows Forms app. However, it throws the exception when it runs as a
Windows service under the local service account. If I run it as a Windows
service under my account it works fine.

The problem only occurs on versions of the application I have built in the
last week. If I install the application using an old MSI file it runs fine.
If I run the app's setup project (in Visual Studio) to create a new MSI file
then install the app using that new MSI file I get the exception when I run
it as a Windows service.

As the problem seems to be related to the account the Windows service is
running under I assume the problem is to do with permissions. Since it was
never a problem until a week ago I assume the system admins have made some
change. Unfortunately I haven't been able to find an admin who admits to
making any change (I worded this carefully as there are system admins in 3
cities who could have done it and I can't track them all down).

If I can go to the system admins with a definite (or even a probable) cause
I hope I can convince them to take the problem seriously and help me work out
a solution.

Cheers
Simon
.



Relevant Pages

  • RE: can a service map a network share to a drive letter
    ... account your mapping drive Windows Service runs and how do you use the Task ... Scheduler(what account does it run). ... If your Windows Service runs under Local System, ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.framework)
  • Re: Windows Service Cannot Move Files
    ... Are you sure that the account has write access to the directory and files? ... The windows service can see the original files, ... XP there is a network version of the system account you can use. ... The files are on the network, so we though the local system ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Windows Service Cannot Move Files
    ... Please verify both the share permissions and the NTFS permissions. ... Mike Ober. ... The windows service can see the original files, ... I actually changed the account that starts it to a domain admin ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Windows Service Cannot Move Files
    ... dermot ha scritto: ... I actually changed the account that starts it to a domain admin ... XP there is a network version of the system account you can use. ... why windows service cannot do the same. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Windows Services - COM
    ... The windows service does emailing, logging to text file,> logging to eventlogs etc through system.diagnostics as well as calls web> services. ... when running under local system or local administrator it> fails with when attempting to instanciate the COM object with... ... > I need to understand why this is failing because ideally i need to run under> a local system account not a domain account. ... > Aaron W.> ...
    (microsoft.public.dotnet.framework.aspnet.security)