Re: Error Verifying Xml Digital Signature

From: Aaron (
Date: 08/22/02

From: (Aaron)
Date: 22 Aug 2002 01:10:03 -0700

Found the fix after trawling through this newsgroup.

Just in case other people are looking the fix is,

CspParameters cspParam = new CspParameters();
cspParam.Flags = CspProviderFlags.UseMachineKeyStore;
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(cspParam);

Apparently the default constructor for the RSA or DSA provider tries
to open the current users key store as part of its constructor. This
works ok on a client application but not for the non interactive user. The above code switches the constructor to using the
machine store instead.

Thanks to the original poster. (Aaron) wrote in message news:<>...
> Hello,
> I am getting an error when I verify an xml digital signature in a web
> service, the verification suceeds outside of the environment.
> The error reported is,
> "... CryptoAPI cryptographic servie provider (CSP) for this
> implementation could not be acquired. at
> System.Security.Cryptography.RSACryptoServiceProvider..ctor() ... "
> The code I am using is shown below. The digital signature has been
> generated and saved to file (using the SignedXml class).
> XmlDocument xmlSigned = new XmlDocument();
> xmlSigned.Load(SigFileName);
> SignedXml signedXml = new SignedXml();
> Error Here ==> signedXml.LoadXml((XmlElement)xmlSigned.DocumentElement)
> return ignedXml.CheckSignature();
> I get the same error using a DSA key instead of an RSA key. I have
> also changed the code access permissions of the assembly to full
> access in case it was a problem with permissions to unmanaged code but
> this made no difference.
> Thanks,
> Aaron Clauson

Relevant Pages