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:

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.

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()
        public override void GenerateKey()
                _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:");
                throw new ApplicationException(sb.ToString(), e);

Open in new window


Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 1 Comment.
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>


Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 1 Comment.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004