RSACryptoServiceProvider.CspKeyContainerInfo プロパティ

定義

暗号化キーの組に関する追加情報を説明する CspKeyContainerInfo オブジェクトを取得します。

C#
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public System.Security.Cryptography.CspKeyContainerInfo CspKeyContainerInfo { get; }
C#
public System.Security.Cryptography.CspKeyContainerInfo CspKeyContainerInfo { get; }
C#
[System.Runtime.InteropServices.ComVisible(false)]
public System.Security.Cryptography.CspKeyContainerInfo CspKeyContainerInfo { get; }

プロパティ値

暗号化キーの組に関する追加情報を説明する CspKeyContainerInfo オブジェクト。

実装

属性

次のコード例では、 プロパティを呼び出す方法を CspKeyContainerInfo 示します。

C#
using System;
using System.Security.Cryptography;
using System.Text;

public class CspKeyContainerInfoExample
{

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

        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 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();

            Console.WriteLine("CspKeyContainerInfo information:");

            Console.WriteLine();

            // 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)
        {
            Console.WriteLine(e.ToString());
        }
        finally
        {
            // Clear the key.
            rsa.Clear();
        }
    }
}

注釈

プロパティを使用して、 CspKeyContainerInfo 暗号化キー ペアに関する追加情報を取得します。 返される CspKeyContainerInfo オブジェクトは、キーがエクスポート可能かどうかを示し、キー コンテナー名、プロバイダーに関する情報、およびその他の情報を指定します。

ランダムなキーが生成された場合、キーを使用するメソッドを呼び出すまで、キー コンテナーは作成されません。 キー コンテナーが CspKeyContainerInfo 作成されていない場合、 CspKeyContainerInfo プロパティによって返されるオブジェクトの一部のプロパティは を CryptographicException スローします。 キー コンテナーが作成されていることを確認するには、 プロパティを呼び出す前に、、 SignDataDecryptSignHashなどのEncryptメソッドをCspKeyContainerInfo呼び出します。

適用対象

製品 バージョン
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

こちらもご覧ください