Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

DSACryptoServiceProvider.CspKeyContainerInfo Property

Gets a CspKeyContainerInfo object that describes additional information about a cryptographic key pair.

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

[ComVisibleAttribute(false)]
public CspKeyContainerInfo CspKeyContainerInfo { get; }

Property Value

Type: System.Security.Cryptography.CspKeyContainerInfo
A CspKeyContainerInfo object that describes additional information about a cryptographic key pair.

Implements

ICspAsymmetricAlgorithm.CspKeyContainerInfo

Use the CspKeyContainerInfo property to retrieve additional information about a cryptographic key pair. The returned CspKeyContainerInfo object describes whether the key is exportable, and specifies the key container name, information about the provider, and other information.

In cases where a random key is generated, a key container will not be created until you call a method that uses the key. Some properties of the CspKeyContainerInfo object returned by the CspKeyContainerInfo property will throw a CryptographicException if a key container has not been created. To make sure that a key container has been created, call a method such as SignData, SignHash, VerifyData, VerifyHash, and so on, before you call the CspKeyContainerInfo property.

The following code example demonstrates how to call the CspKeyContainerInfo property.


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


public class CspKeyContainerInfoExample
{

    public static void Main(String[] args)
    {
        DSACryptoServiceProvider dsa= new DSACryptoServiceProvider();

        try
        {
            // 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 SignData 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 sign.";

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

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

            byte[] sData = dsa.SignData(byteData, 0, byteData.Length);

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

            Console.WriteLine();

            Console.WriteLine("CspKeyContainerInfo information:");

            Console.WriteLine();

            // Create a new CspKeyContainerInfo object.
            CspKeyContainerInfo keyInfo = dsa.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)
        {
            Console.WriteLine(e.ToString());
        }
        finally
        {
            // Clear the key.
            dsa.Clear();
        }
        Console.ReadLine();
    }
}


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2015 Microsoft