CspParameters 建構函式

定義

初始化 CspParameters 類別的新執行個體。

多載

CspParameters()

初始化 CspParameters 類別的新執行個體。

CspParameters(Int32)

使用指定的提供者類型碼,來初始化 CspParameters 類別的新執行個體。

CspParameters(Int32, String)

使用指定的提供者類型程式碼和名稱,來初始化 CspParameters 類別的新執行個體。

CspParameters(Int32, String, String)

使用指定的提供者類型程式碼和名稱,以及指定的容器名稱,初始化 CspParameters 類別的新執行個體。

CspParameters(Int32, String, String, CryptoKeySecurity, IntPtr)

使用提供者類型、提供者名稱、容器名稱、存取資訊和 Unmanaged 智慧卡密碼對話方塊的控制代碼,初始化 CspParameters 類別的新執行個體。

CspParameters(Int32, String, String, CryptoKeySecurity, SecureString)

使用提供者類型、提供者名稱、容器名稱、存取資訊和與智慧卡金鑰關聯的密碼,初始化 CspParameters 類別的新執行個體。

CspParameters()

來源:
CspParameters.cs
來源:
CspParameters.cs
來源:
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)

來源:
CspParameters.cs
來源:
CspParameters.cs
來源:
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 標頭檔中:

  • 若要指定與 RSA 演算法相容的提供者,請將 的值 1 傳遞至 dwTypeIn 參數。

  • 若要指定與 DSA 演算法相容的提供者,請將 的值 13 傳遞至 dwTypeIn 參數。

如需其他提供者類型值的相關資訊,請參閱 ProviderType 欄位。 如需預設提供者類型和其行為的詳細資訊,請參閱 Microsoft 密碼編譯 API (CAPI) 檔

另請參閱

適用於

CspParameters(Int32, String)

來源:
CspParameters.cs
來源:
CspParameters.cs
來源:
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 標頭檔中:

  • 若要指定與 RSA 演算法相容的提供者,請將 的值 1 傳遞至 dwTypeIn 參數。

  • 若要指定與 DSA 演算法相容的提供者,請將 的值 13 傳遞至 dwTypeIn 參數。

如需其他提供者類型值的相關資訊,請參閱 ProviderType 欄位。 如需預設提供者類型和其行為的詳細資訊,請參閱 Microsoft 密碼編譯 API (CAPI) 檔

另請參閱

適用於

CspParameters(Int32, String, String)

來源:
CspParameters.cs
來源:
CspParameters.cs
來源:
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 標頭檔中:

  • 若要指定與 RSA 演算法相容的提供者,請將 的值 1 傳遞至 dwTypeIn 參數。

  • 若要指定與 DSA 演算法相容的提供者,請將 的值 13 傳遞至 dwTypeIn 參數。

如需其他提供者類型值的相關資訊,請參閱 ProviderType 欄位。 如需預設提供者類型和其行為的詳細資訊,請參閱 Microsoft 密碼編譯 API (CAPI) 檔

另請參閱

適用於

CspParameters(Int32, String, String, CryptoKeySecurity, IntPtr)

使用提供者類型、提供者名稱、容器名稱、存取資訊和 Unmanaged 智慧卡密碼對話方塊的控制代碼,初始化 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 標頭檔中:

  • 若要指定與 RSA 演算法相容的提供者,請將 的值 1 傳遞至 dwTypeIn 參數。

  • 若要指定與 DSA 演算法相容的提供者,請將 的值 13 傳遞至 dwTypeIn 參數。

如需其他提供者類型值的相關資訊,請參閱 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 標頭檔中:

  • 若要指定與 RSA 演算法相容的提供者,請將 的值 1 傳遞至 dwTypeIn 參數。

  • 若要指定與 DSA 演算法相容的提供者,請將 的值 13 傳遞至 dwTypeIn 參數。

如需其他提供者類型值的相關資訊,請參閱 ProviderType 欄位。 如需預設提供者類型和其行為的詳細資訊,請參閱 Microsoft 密碼編譯 API (CAPI) 檔

適用於