how to export rsa key container in c#

Discussion in 'C#' started by imported_vihrao, Aug 28, 2010.

  1. imported_vihrao

    imported_vihrao New Member

    Joined:
    Aug 28, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice