Retrieve RSA Keys

Discussion in 'ASP.NET / ASP.NET Core' started by GBiggs, Mar 25, 2012.

  1. We use the RsaProtectedConfigurationProvider to encrypt the connection strings in web.config. Our private key is in a key locker on the server. All of this was accomplished by following the KB instructions.

    We would like to use the key pair for some other encryption tasks. I assume this is possible. I've tested retrieving the key with the sample code in the link below but can't get it to work: http://msdn.microsoft.com/en-us/library/tswxhw92(v=vs.85).aspx

    Sample code from this page:
    public static void GetKeyFromContainer(string ContainerName)
    {
    // Create the CspParameters object and set the key container
    // name used to store the RSA key pair.
    CspParameters cp = new CspParameters();
    cp.KeyContainerName = ContainerName;

    // Create a new instance of RSACryptoServiceProvider that accesses
    // the key container MyKeyContainerName.
    RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(cp);

    // Display the key information to the console.
    Console.WriteLine("Key retrieved from container : \n {0}", rsa.ToXmlString(true));
    }
     

Share This Page