troubleshooting Question

RSACryptoProvider class problem when called from within a web service

Avatar of tom_isacson
tom_isacson asked on
.NET ProgrammingWCF
1 Comment1 Solution645 ViewsLast Modified:
Hello,

I have a web service that creates an instance of the System.Security.Cryptography.RSACryptoProvider class.  When I deploy this service to an IIS6.0 server and execute it under an app pool whose identity is set to a machine specific user (which was added to the IIS_WPG group), I cannot execute the method ToXMLString().  I am getting a "The system cannot find the file specified" error.

When I point my test project's web reference to the web service in my VS 2008 solution, I have no problems. When I point my test project's web reference to the web service deployed on my local machine's IIS 5.1, again I have no problems.

I suspect a permissions issue is the most likely cause.  However, I cannot determine where or why a file is attempting to be referenced when I call the ToXMLString() method - so I don't know what, if any, permissions need to be modified.  

I am not persisting the keys into a KeyContainer - I simply generate a random key pair (by instantiating the RSACryptoProvider class) and then am trying to save the Public Key into a local variable.  In addition, when I examine the CspKeyContainerInfo class at run time after the RSACryptoProvider object has been created, nothing seems unusual (for example, Accessible = true, Exportable = true, MachineKeyStore = false ).

Any advice would be much appreciated.

Thanks,
Tom Isacson


using System;
using System.Security.Cryptography;
using System.Text;    
 
  public class RSAProvider : AsymmetricBase
    {
        private RSACryptoServiceProvider _rsa;
        private string _privatekey;
        private string _publickey;
        private int _keyid;
 
        public RSAProvider()
        {
            Initialize();
            this.GenerateKey(); 
        }
 
        public override void GenerateKey()
        {
            try
            {
                _rsa = new RSACryptoServiceProvider();
 
                this._privatekey = _rsa.ToXmlString(true);
                this._publickey = _rsa.ToXmlString(false);
                this._keyid = -1;
            }
            catch (Exception e)
            {
                StringBuilder sb = new StringBuilder();
 
                sb.AppendLine("Error in GenerateKey() method.");
                sb.AppendLine("Inner Message:");
                sb.AppendLine(e.Message);
 
                throw new ApplicationException(sb.ToString(), e);
            }
        }
 
   }
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 1 Comment.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros