Avatar of tom_isacson
tom_isacson

asked on 

RSACryptoProvider class problem when called from within a web service

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);
            }
        }
 
   }

Open in new window

.NET ProgrammingWCF

Avatar of undefined
Last Comment
tom_isacson
ASKER CERTIFIED SOLUTION
Avatar of tom_isacson
tom_isacson

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo