語言

CspParameters 建構函式

定義

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

多載

名稱 Description
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()

來源:
CspParameters.cs
來源:
CspParameters.cs
來源:
CspParameters.cs
來源:
CspParameters.cs
來源:
CspParameters.cs

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

public:
 CspParameters();
public CspParameters();
Public Sub New ()

範例

以下範例使用該 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

備註

這種形式 CspParameters 將欄位初始 ProviderType 化為 ,該值 24指定PROV_RSA_AES提供者。 此預設提供者與 Aes 演算法相容。

如需其他提供者類型的資訊,請參閱該 ProviderType 欄位。

另請參閱

適用於

CspParameters(Int32)

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

使用提供者類型、提供者名稱、容器名稱、存取資訊及非管理型智慧卡密碼對話框的代柄初始化該類別的新實例 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)文件。

適用於