CspKeyContainerInfo Constructor (CspParameters)


Initializes a new instance of the CspKeyContainerInfo class using the specified parameters.

Namespace:   System.Security.Cryptography
Assembly:  mscorlib (in mscorlib.dll)

public CspKeyContainerInfo(
	CspParameters parameters


Type: System.Security.Cryptography.CspParameters

A CspParameters object that provides information about the key.

The following code example creates a key container and retrieves information about that container.

using System;
using System.Security.Cryptography;
using System.Text;

public class CspKeyContainerInfoExample

    public static void Main(String[] args)
        RSACryptoServiceProvider rsa= new RSACryptoServiceProvider();

            // Note: In cases where a random key is generated,   
            // a key container is not created until you call  
            // a method that uses the key.  This example calls
            // the Encrypt method before calling the
            // CspKeyContainerInfo property so that a key
            // container is created.  

            // Create some data to encrypt and display it.
            string data = "Here is some data to encrypt.";

            Console.WriteLine("Data to encrypt: " + data);

            // Convert the data to an array of bytes and 
            // encrypt it.
            byte[] byteData = Encoding.ASCII.GetBytes(data);

            byte[] encData = rsa.Encrypt(byteData, false);

            // Display the encrypted value.
            Console.WriteLine("Encrypted Data: " + Encoding.ASCII.GetString(encData));


            Console.WriteLine("CspKeyContainerInfo information:");


            // Create a new CspKeyContainerInfo object.
            CspKeyContainerInfo keyInfo = rsa.CspKeyContainerInfo;

            // Display the value of each property.

            Console.WriteLine("Accessible property: " + keyInfo.Accessible);

            Console.WriteLine("Exportable property: " + keyInfo.Exportable);

            Console.WriteLine("HardwareDevice property: " + keyInfo.HardwareDevice);

            Console.WriteLine("KeyContainerName property: " + keyInfo.KeyContainerName);

            Console.WriteLine("KeyNumber property: " + keyInfo.KeyNumber.ToString());

            Console.WriteLine("MachineKeyStore property: " + keyInfo.MachineKeyStore);

            Console.WriteLine("Protected property: " + keyInfo.Protected);

            Console.WriteLine("ProviderName property: " + keyInfo.ProviderName);

            Console.WriteLine("ProviderType property: " + keyInfo.ProviderType);

            Console.WriteLine("RandomlyGenerated property: " + keyInfo.RandomlyGenerated);

            Console.WriteLine("Removable property: " + keyInfo.Removable);

            Console.WriteLine("UniqueKeyContainerName property: " + keyInfo.UniqueKeyContainerName);

        catch (Exception e)
            // Clear the key.

.NET Framework
Available since 2.0
Windows Phone Silverlight
Available since 7.1
Return to top