Share via


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 필드를 사용하여 키 컨테이너의 이름을 지정합니다. 컨테이너 이름을 사용하여 해당 컨테이너 내에서 지속형 키를 검색할 수 있습니다.

키 컨테이너를 만드는 방법에 대한 자세한 내용은 방법: 키 컨테이너에 비대칭 키 저장을 참조하세요.

적용 대상

추가 정보