CspParameters.KeyContainerName フィールド

定義

CspParameters のキー コンテナー名を表します。

public: System::String ^ KeyContainerName;
public string? KeyContainerName;
public string KeyContainerName;
val mutable KeyContainerName : string
Public KeyContainerName As String 

フィールド値

次のコード例では、 クラスを使用してキー コンテナーを CspParameters 作成し、コンテナーにキーを保存します。

using namespace System;
using namespace System::IO;
using namespace System::Security::Cryptography;
int main()
{
   
   // creates the CspParameters object and sets the key container name used to store the RSA key pair
   CspParameters^ cp = gcnew CspParameters;
   cp->KeyContainerName = "MyKeyContainerName";
   
   // instantiates the rsa instance accessing the key container MyKeyContainerName
   RSACryptoServiceProvider^ rsa = gcnew RSACryptoServiceProvider( cp );
   
   // add the below line to delete the key entry in MyKeyContainerName
   // rsa.PersistKeyInCsp = false;
   //writes out the current key pair used in the rsa instance
   Console::WriteLine( "Key is : \n{0}", rsa->ToXmlString( true ) );
}
using System;
using System.IO;
using System.Security.Cryptography;

public class StoreKey
{
    public static void Main()
    {
        // creates the CspParameters object and sets the key container name used to store the RSA key pair
        CspParameters cp = new CspParameters();
        cp.KeyContainerName = "MyKeyContainerName";

        // instantiates the rsa instance accessing the key container MyKeyContainerName
        RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(cp);
        // add the below line to delete the key entry in MyKeyContainerName
        // rsa.PersistKeyInCsp = false;

        //writes out the current key pair used in the rsa instance
        Console.WriteLine("Key is : \n" + rsa.ToXmlString(true));
    }
}
Imports System.IO
Imports System.Security.Cryptography



Public Class StoreKey
    
    Public Shared Sub Main()
        ' creates the CspParameters object and sets the key container name used to store the RSA key pair
        Dim cp As New CspParameters()
        cp.KeyContainerName = "MyKeyContainerName"
        
        ' instantiates the rsa instance accessing the key container MyKeyContainerName
        Dim rsa As New RSACryptoServiceProvider(cp)
        ' add the below line to delete the key entry in MyKeyContainerName
        ' rsa.PersistKeyInCsp = false;
        'writes out the current key pair used in the rsa instance
        Console.WriteLine("Key is : "  & rsa.ToXmlString(True))
    End Sub
End Class

注釈

フィールドを KeyContainerName 使用して、キー コンテナーの名前を指定します。 コンテナー名を使用して、そのコンテナー内の永続化されたキーを取得できます。

キー コンテナーの作成の詳細については、「 方法: キー コンテナーに非対称キーを格納する」を参照してください。

適用対象

こちらもご覧ください