vihrao 0 Newbie Poster

I want to create a rsa key in c# and export the container. I am having difficulty. I create container like this:

CspParameters cspParams = new CspParameters();
            cspParams.KeyContainerName = "XML_ENC_RSA_KEY";

The msdn example says I can export the container with this syntax:
aspnet_regiis -pa "XML_ENC_RSA_KEY" "NT AUTHORITY\NETWORK SERVICE". This does not work on my XP Host PC. I belive this is applicable for Windows 2003 Server.
1) So what is the correct syntax for exporting rsa key container from XP host?

Also to get aspnet_regiis.exe path I did something like this:

string winPath = Environment.GetEnvironmentVariable("windir");
       string fullPath = winPath + @"\Microsoft.NET\Framework\v2.0.50727" + @"\aspnet_regiis.exe";

But this path may be different for each host, based on the .NET verison installation.
2) Is there a way to get the aspnet_regiis.exe path from registry or a environment varaible?

Once I get the path to aspnet_regiis.exe I want to invokve it from c# like this.
3) Is this code correct?

ProcessStartInfo startInfo = new ProcessStartInfo(fullPath);
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            startInfo.UseShellExecute = false;
            startInfo.RedirectStandardOutput = true;
            startInfo.RedirectStandardError = true;

            System.Diagnostics.Process process = new System.Diagnostics.Process();
            startInfo.Arguments = args;
            process.StartInfo = startInfo;
            process.Start();
            process.WaitForExit();

Can someone please help me?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.