CspParameters.KeyContainerName 字段    
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示 CspParameters 的密钥容器名称。
public: System::String ^ KeyContainerName;public string? KeyContainerName;public string KeyContainerName;val mutable KeyContainerName : stringPublic KeyContainerName As String 字段值
示例
下面的代码示例使用 类创建密钥容器, CspParameters 并将密钥保存在容器中。
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使用 字段指定密钥容器的名称。 可以使用容器名称检索该容器中的持久化密钥。
有关创建密钥容器的详细信息,请参阅 如何:在密钥容器中存储非对称密钥。