CspParameters 构造函数 
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 CspParameters 类的新实例。
重载
| CspParameters() | 
						 初始化 CspParameters 类的新实例。  | 
        	
| CspParameters(Int32) | 
						 使用指定的提供程序类型代码初始化 CspParameters 类的新实例。  | 
        	
| CspParameters(Int32, String) | 
						 使用指定的提供程序类型代码和名称初始化 CspParameters 类的新实例。  | 
        	
| CspParameters(Int32, String, String) | 
						 使用指定的提供程序类型代码和名称以及指定的容器名称初始化 CspParameters 类的新实例。  | 
        	
| CspParameters(Int32, String, String, CryptoKeySecurity, IntPtr) | 
						 使用提供程序类型、提供程序名称、容器名称、访问信息以及非托管智能卡密码对话框的句柄初始化 CspParameters 类的新实例。  | 
        	
| CspParameters(Int32, String, String, CryptoKeySecurity, SecureString) | 
						 使用提供程序类型、提供程序名称、容器名称、访问信息以及与智能卡密钥相关的密码初始化 CspParameters 类的新实例。  | 
        	
CspParameters()
- Source:
 - CspParameters.cs
 
- Source:
 - CspParameters.cs
 
- Source:
 - CspParameters.cs
 
初始化 CspParameters 类的新实例。
public:
 CspParameters();
	public CspParameters ();
	Public Sub New ()
  示例
下面的代码示例使用 类创建密钥容器, 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
    	注解
这种形式的 CspParameters 将 ProviderType 字段初始化为 值 24,该值指定PROV_RSA_AES提供程序。  此默认提供程序与 Aes 算法兼容。
有关其他提供程序类型的信息,请参阅 ProviderType 字段。
另请参阅
适用于
CspParameters(Int32)
- Source:
 - CspParameters.cs
 
- Source:
 - CspParameters.cs
 
- Source:
 - CspParameters.cs
 
使用指定的提供程序类型代码初始化 CspParameters 类的新实例。
public:
 CspParameters(int dwTypeIn);
	public CspParameters (int dwTypeIn);
	new System.Security.Cryptography.CspParameters : int -> System.Security.Cryptography.CspParameters
	Public Sub New (dwTypeIn As Integer)
	参数
- dwTypeIn
 - Int32
 
指定要创建的提供程序类型的提供程序类型代码。
注解
CspParameters使用 构造函数通过传递表示该提供程序的数值来指定提供程序类型。 表示默认提供程序类型的数值在 WinCrypt.h 头文件中定义:
有关其他提供程序类型值的信息,请参阅 ProviderType 字段。 有关默认提供程序类型及其行为的详细信息,请参阅 Microsoft 加密 API (CAPI) 文档。
另请参阅
适用于
CspParameters(Int32, String)
- Source:
 - CspParameters.cs
 
- Source:
 - CspParameters.cs
 
- Source:
 - CspParameters.cs
 
使用指定的提供程序类型代码和名称初始化 CspParameters 类的新实例。
public:
 CspParameters(int dwTypeIn, System::String ^ strProviderNameIn);
	public CspParameters (int dwTypeIn, string? strProviderNameIn);
	public CspParameters (int dwTypeIn, string strProviderNameIn);
	new System.Security.Cryptography.CspParameters : int * string -> System.Security.Cryptography.CspParameters
	Public Sub New (dwTypeIn As Integer, strProviderNameIn As String)
	参数
- dwTypeIn
 - Int32
 
指定要创建的提供程序类型的提供程序类型代码。
- strProviderNameIn
 - String
 
提供程序名称。
示例
下面的代码示例使用 CspParameters 类来选择智能卡加密服务提供程序。 然后,它使用智能卡对数据进行签名和验证。
using namespace System;
using namespace System::Security::Cryptography;
int main()
{
   
   // To idendify the Smart Card CryptoGraphic Providers on your
   // computer, use the Microsoft Registry Editor (Regedit.exe).
   // The available Smart Card CryptoGraphic Providers are listed
   // in HKEY_LOCAL_MACHINE\Software\Microsoft\Cryptography\Defaults\Provider.
   // Create a new CspParameters object that identifies a 
   // Smart Card CryptoGraphic Provider.
   // The 1st parameter comes from HKEY_LOCAL_MACHINE\Software\Microsoft\Cryptography\Defaults\Provider Types.
   // The 2nd parameter comes from HKEY_LOCAL_MACHINE\Software\Microsoft\Cryptography\Defaults\Provider.
   CspParameters^ csp = gcnew CspParameters( 1,L"Schlumberger Cryptographic Service Provider" );
   csp->Flags = CspProviderFlags::UseDefaultKeyContainer;
   
   // Initialize an RSACryptoServiceProvider object using
   // the CspParameters object.
   RSACryptoServiceProvider^ rsa = gcnew RSACryptoServiceProvider( csp );
   
   // Create some data to sign.
   array<Byte>^data = gcnew array<Byte>{
      0,1,2,3,4,5,6,7
   };
   Console::WriteLine( L"Data			: {0}", BitConverter::ToString( data ) );
   
   // Sign the data using the Smart Card CryptoGraphic Provider.
   array<Byte>^sig = rsa->SignData( data, L"SHA256" );
   Console::WriteLine( L"Signature	: {0}", BitConverter::ToString( sig ) );
   
   // Verify the data using the Smart Card CryptoGraphic Provider.
   bool verified = rsa->VerifyData( data, L"SHA256", sig );
   Console::WriteLine( L"Verified		: {0}", verified );
}
using System;
using System.Security.Cryptography;
namespace SmartCardSign
{
    class SCSign
    {
        static void Main(string[] args)
        {
            // To idendify the Smart Card CryptoGraphic Providers on your
            // computer, use the Microsoft Registry Editor (Regedit.exe).
            // The available Smart Card CryptoGraphic Providers are listed
            // in HKEY_LOCAL_MACHINE\Software\Microsoft\Cryptography\Defaults\Provider.
            // Create a new CspParameters object that identifies a
            // Smart Card CryptoGraphic Provider.
            // The 1st parameter comes from HKEY_LOCAL_MACHINE\Software\Microsoft\Cryptography\Defaults\Provider Types.
            // The 2nd parameter comes from HKEY_LOCAL_MACHINE\Software\Microsoft\Cryptography\Defaults\Provider.
            CspParameters csp = new CspParameters(1, "Schlumberger Cryptographic Service Provider");
            csp.Flags = CspProviderFlags.UseDefaultKeyContainer;
            // Initialize an RSACryptoServiceProvider object using
            // the CspParameters object.
            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(csp);
            // Create some data to sign.
            byte[] data = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 };
            Console.WriteLine("Data			: " + BitConverter.ToString(data));
            // Sign the data using the Smart Card CryptoGraphic Provider.
            byte[] sig = rsa.SignData(data, "SHA256");
            Console.WriteLine("Signature	: " + BitConverter.ToString(sig));
            // Verify the data using the Smart Card CryptoGraphic Provider.
            bool verified = rsa.VerifyData(data, "SHA256", sig);
            Console.WriteLine("Verified		: " + verified);
        }
    }
}
Imports System.Security.Cryptography
Module SCSign
    Sub Main(ByVal args() As String)
        ' To idendify the Smart Card CryptoGraphic Providers on your
        ' computer, use the Microsoft Registry Editor (Regedit.exe).
        ' The available Smart Card CryptoGraphic Providers are listed
        ' in HKEY_LOCAL_MACHINE\Software\Microsoft\Cryptography\Defaults\Provider.
        ' Create a new CspParameters object that identifies a 
        ' Smart Card CryptoGraphic Provider.
        ' The 1st parameter comes from HKEY_LOCAL_MACHINE\Software\Microsoft\Cryptography\Defaults\Provider Types.
        ' The 2nd parameter comes from HKEY_LOCAL_MACHINE\Software\Microsoft\Cryptography\Defaults\Provider.
        Dim csp As New CspParameters(1, "Schlumberger Cryptographic Service Provider")
        csp.Flags = CspProviderFlags.UseDefaultKeyContainer
        ' Initialize an RSACryptoServiceProvider object using
        ' the CspParameters object.
        Dim rsa As New RSACryptoServiceProvider(csp)
        ' Create some data to sign.
        Dim data() As Byte = {0, 1, 2, 3, 4, 5, 6, 7}
        Console.WriteLine("Data   : " + BitConverter.ToString(data))
        ' Sign the data using the Smart Card CryptoGraphic Provider.
        Dim sig As Byte() = rsa.SignData(data, "SHA256")
        Console.WriteLine("Signature : " + BitConverter.ToString(sig))
        ' Verify the data using the Smart Card CryptoGraphic Provider.
        Dim verified As Boolean = rsa.VerifyData(data, "SHA256", sig)
        Console.WriteLine("Verified")
    End Sub
End Module
    	注解
CspParameters使用 构造函数指定提供程序类型和名称。
通过传递表示所需提供程序类型的数值来指定提供程序类型。 表示默认提供程序类型的数值在 WinCrypt.h 头文件中定义:
有关其他提供程序类型值的信息,请参阅 ProviderType 字段。 有关默认提供程序类型及其行为的详细信息,请参阅 Microsoft 加密 API (CAPI) 文档。
另请参阅
适用于
CspParameters(Int32, String, String)
- Source:
 - CspParameters.cs
 
- Source:
 - CspParameters.cs
 
- Source:
 - CspParameters.cs
 
使用指定的提供程序类型代码和名称以及指定的容器名称初始化 CspParameters 类的新实例。
public:
 CspParameters(int dwTypeIn, System::String ^ strProviderNameIn, System::String ^ strContainerNameIn);
	public CspParameters (int dwTypeIn, string? strProviderNameIn, string? strContainerNameIn);
	public CspParameters (int dwTypeIn, string strProviderNameIn, string strContainerNameIn);
	new System.Security.Cryptography.CspParameters : int * string * string -> System.Security.Cryptography.CspParameters
	Public Sub New (dwTypeIn As Integer, strProviderNameIn As String, strContainerNameIn As String)
	参数
- dwTypeIn
 - Int32
 
指定要创建的提供程序类型的提供程序类型代码。
- strProviderNameIn
 - String
 
提供程序名称。
- strContainerNameIn
 - String
 
容器名称。
注解
CspParameters使用 构造函数指定提供程序类型、提供程序名称和容器名称。
可以使用容器名称检索该容器中的密钥。
通过传递表示所需提供程序类型的数值来指定提供程序类型。 表示默认提供程序类型的数值在 WinCrypt.h 头文件中定义:
有关其他提供程序类型值的信息,请参阅 ProviderType 字段。 有关默认提供程序类型及其行为的详细信息,请参阅 Microsoft 加密 API (CAPI) 文档。
另请参阅
适用于
CspParameters(Int32, String, String, CryptoKeySecurity, IntPtr)
使用提供程序类型、提供程序名称、容器名称、访问信息以及非托管智能卡密码对话框的句柄初始化 CspParameters 类的新实例。
public:
 CspParameters(int providerType, System::String ^ providerName, System::String ^ keyContainerName, System::Security::AccessControl::CryptoKeySecurity ^ cryptoKeySecurity, IntPtr parentWindowHandle);
	public CspParameters (int providerType, string providerName, string keyContainerName, System.Security.AccessControl.CryptoKeySecurity cryptoKeySecurity, IntPtr parentWindowHandle);
	new System.Security.Cryptography.CspParameters : int * string * string * System.Security.AccessControl.CryptoKeySecurity * nativeint -> System.Security.Cryptography.CspParameters
	Public Sub New (providerType As Integer, providerName As String, keyContainerName As String, cryptoKeySecurity As CryptoKeySecurity, parentWindowHandle As IntPtr)
	参数
- providerType
 - Int32
 
指定要创建的提供程序类型的提供程序类型代码。
- providerName
 - String
 
提供程序名称。
- keyContainerName
 - String
 
容器名称。
- cryptoKeySecurity
 - CryptoKeySecurity
 
表示容器的访问权限及审核规则的对象。
- parentWindowHandle
 - 
				
				IntPtr
nativeint
 
智能卡密码对话框的父级窗口的句柄。
注解
可以使用容器名称检索该容器中的密钥。
通过传递表示所需提供程序类型的数值来指定提供程序类型。 表示默认提供程序类型的数值在 WinCrypt.h 头文件中定义:
有关其他提供程序类型值的信息,请参阅 ProviderType 字段。 有关默认提供程序类型及其行为的详细信息,请参阅 Microsoft 加密 API (CAPI) 文档。
适用于
CspParameters(Int32, String, String, CryptoKeySecurity, SecureString)
使用提供程序类型、提供程序名称、容器名称、访问信息以及与智能卡密钥相关的密码初始化 CspParameters 类的新实例。
public:
 CspParameters(int providerType, System::String ^ providerName, System::String ^ keyContainerName, System::Security::AccessControl::CryptoKeySecurity ^ cryptoKeySecurity, System::Security::SecureString ^ keyPassword);
	public CspParameters (int providerType, string providerName, string keyContainerName, System.Security.AccessControl.CryptoKeySecurity cryptoKeySecurity, System.Security.SecureString keyPassword);
	new System.Security.Cryptography.CspParameters : int * string * string * System.Security.AccessControl.CryptoKeySecurity * System.Security.SecureString -> System.Security.Cryptography.CspParameters
	Public Sub New (providerType As Integer, providerName As String, keyContainerName As String, cryptoKeySecurity As CryptoKeySecurity, keyPassword As SecureString)
	参数
- providerType
 - Int32
 
指定要创建的提供程序类型的提供程序类型代码。
- providerName
 - String
 
提供程序名称。
- keyContainerName
 - String
 
容器名称。
- cryptoKeySecurity
 - CryptoKeySecurity
 
表示容器的访问权限及审核规则的对象。
- keyPassword
 - SecureString
 
与智能卡密钥相关的密码。
注解
可以使用容器名称检索该容器中的密钥。
通过传递表示所需提供程序类型的数值来指定提供程序类型。 表示默认提供程序类型的数值在 WinCrypt.h 头文件中定义:
有关其他提供程序类型值的信息,请参阅 ProviderType 字段。 有关默认提供程序类型及其行为的详细信息,请参阅 Microsoft 加密 API (CAPI) 文档。