CspParameters Constructors

Definition

Initializes a new instance of the CspParameters class.

Overloads

CspParameters()

Initializes a new instance of the CspParameters class.

CspParameters(Int32)

Initializes a new instance of the CspParameters class with the specified provider type code.

CspParameters(Int32, String)

Initializes a new instance of the CspParameters class with the specified provider type code and name.

CspParameters(Int32, String, String)

Initializes a new instance of the CspParameters class with the specified provider type code and name, and the specified container name.

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

Initializes a new instance of the CspParameters class using a provider type, a provider name, a container name, access information, and a handle to an unmanaged smart card password dialog.

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

Initializes a new instance of the CspParameters class using a provider type, a provider name, a container name, access information, and a password associated with a smart card key.

CspParameters()

Source:
CspParameters.cs
Source:
CspParameters.cs
Source:
CspParameters.cs

Initializes a new instance of the CspParameters class.

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

Examples

The following code example creates a key container using the CspParameters class and saves the key in the container.

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

Remarks

This form of CspParameters initializes the ProviderType field to a value of 24, which specifies the PROV_RSA_AES provider. This default provider is compatible with the Aes algorithm.

For information about other provider types, see the ProviderType field.

See also

Applies to

CspParameters(Int32)

Source:
CspParameters.cs
Source:
CspParameters.cs
Source:
CspParameters.cs

Initializes a new instance of the CspParameters class with the specified provider type code.

public:
 CspParameters(int dwTypeIn);
public CspParameters (int dwTypeIn);
new System.Security.Cryptography.CspParameters : int -> System.Security.Cryptography.CspParameters
Public Sub New (dwTypeIn As Integer)

Parameters

dwTypeIn
Int32

A provider type code that specifies the kind of provider to create.

Remarks

Use the CspParameters constructor to specify a provider type by passing a numeric value that represents that provider. The numeric values that represent the default provider types are defined in the WinCrypt.h header file:

  • To specify a provider compatible with the RSA algorithm, pass a value of 1 to the dwTypeIn parameter.

  • To specify a provider compatible with the DSA algorithm, pass a value of 13 to the dwTypeIn parameter.

For information about other provider type values, see the ProviderType field. For more information about the default provider types and their behaviors, see the Microsoft Cryptography API (CAPI) documentation.

See also

Applies to

CspParameters(Int32, String)

Source:
CspParameters.cs
Source:
CspParameters.cs
Source:
CspParameters.cs

Initializes a new instance of the CspParameters class with the specified provider type code and name.

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)

Parameters

dwTypeIn
Int32

A provider type code that specifies the kind of provider to create.

strProviderNameIn
String

A provider name.

Examples

The following code example uses the CspParameters class to select a Smart Card Cryptographic Service Provider. It then signs and verifies data using the smart card.

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

Remarks

Use the CspParameters constructor to specify a provider type and name.

Specify a provider type by passing a numeric value that represents the desired provider type. The numeric values that represent the default provider types are defined in the WinCrypt.h header file:

  • To specify a provider compatible with the RSA algorithm, pass a value of 1 to the dwTypeIn parameter.

  • To specify a provider compatible with the DSA algorithm, pass a value of 13 to the dwTypeIn parameter.

For information about other provider type values, see the ProviderType field. For more information about the default provider types and their behaviors, see the Microsoft Cryptography API (CAPI) documentation.

See also

Applies to

CspParameters(Int32, String, String)

Source:
CspParameters.cs
Source:
CspParameters.cs
Source:
CspParameters.cs

Initializes a new instance of the CspParameters class with the specified provider type code and name, and the specified container name.

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)

Parameters

dwTypeIn
Int32

The provider type code that specifies the kind of provider to create.

strProviderNameIn
String

A provider name.

strContainerNameIn
String

A container name.

Remarks

Use the CspParameters constructor to specify a provider type, a provider name, and a container name.

You can use the container name to retrieve a key within that container.

Specify a provider type by passing a numeric value that represents the desired provider type. The numeric values that represent the default provider types are defined in the WinCrypt.h header file:

  • To specify a provider compatible with the RSA algorithm, pass a value of 1 to the dwTypeIn parameter.

  • To specify a provider compatible with the DSA algorithm, pass a value of 13 to the dwTypeIn parameter.

For information about other provider type values, see the ProviderType field. For more information about the default provider types and their behaviors, see the Microsoft Cryptography API (CAPI) documentation.

See also

Applies to

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

Initializes a new instance of the CspParameters class using a provider type, a provider name, a container name, access information, and a handle to an unmanaged smart card password dialog.

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)

Parameters

providerType
Int32

The provider type code that specifies the kind of provider to create.

providerName
String

A provider name.

keyContainerName
String

A container name.

cryptoKeySecurity
CryptoKeySecurity

An object that represents access rights and audit rules for the container.

parentWindowHandle
IntPtr

nativeint

A handle to the parent window for a smart card password dialog.

Remarks

You can use the container name to retrieve a key within that container.

Specify a provider type by passing a numeric value that represents the desired provider type. The numeric values that represent the default provider types are defined in the WinCrypt.h header file:

  • To specify a provider compatible with the RSA algorithm, pass a value of 1 to the dwTypeIn parameter.

  • To specify a provider compatible with the DSA algorithm, pass a value of 13 to the dwTypeIn parameter.

For information about other provider type values, see the ProviderType field. For more information about the default provider types and their behaviors, see the Microsoft Cryptography API (CAPI) documentation.

Applies to

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

Initializes a new instance of the CspParameters class using a provider type, a provider name, a container name, access information, and a password associated with a smart card key.

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)

Parameters

providerType
Int32

The provider type code that specifies the kind of provider to create.

providerName
String

A provider name.

keyContainerName
String

A container name.

cryptoKeySecurity
CryptoKeySecurity

An object that represents access rights and audit rules for a container.

keyPassword
SecureString

A password associated with a smart card key.

Remarks

You can use the container name to retrieve a key within that container.

Specify a provider type by passing a numeric value that represents the desired provider type. The numeric values that represent the default provider types are defined in the WinCrypt.h header file:

  • To specify a provider compatible with the RSA algorithm, pass a value of 1 to the dwTypeIn parameter.

  • To specify a provider compatible with the DSA algorithm, pass a value of 13 to the dwTypeIn parameter.

For information about other provider type values, see the ProviderType field. For more information about the default provider types and their behaviors, see the Microsoft Cryptography API (CAPI) documentation.

Applies to