CspParameters Klasa

Definicja

Zawiera parametry przekazywane do dostawcy usług kryptograficznych (CSP), który wykonuje obliczenia kryptograficzne. Klasa ta nie może być dziedziczona.

public ref class CspParameters sealed
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public sealed class CspParameters
public sealed class CspParameters
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class CspParameters
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
type CspParameters = class
type CspParameters = class
[<System.Runtime.InteropServices.ComVisible(true)>]
type CspParameters = class
Public NotInheritable Class CspParameters
Dziedziczenie
CspParameters
Atrybuty

Przykłady

Poniższy przykład kodu tworzy kontener kluczy przy użyciu CspParameters klasy i zapisuje klucz w kontenerze.

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

Poniższy przykład kodu używa CspParameters klasy do wybrania dostawcy usług kryptograficznych kart inteligentnych. Następnie podpisuje i weryfikuje dane przy użyciu karty inteligentnej.

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

Uwagi

Klasa CspParameters reprezentuje parametry, które można przekazać do zarządzanych klas kryptograficznych, które wewnętrznie używają dostawców usług kryptograficznych firmy Microsoft (CSP) z niezarządzanego interfejsu API kryptografii firmy Microsoft (CAPI). Klasy o nazwach kończących się na "CryptoServiceProvider" to otoki kodu zarządzanego dla odpowiedniego dostawcy usług kryptograficznych.

CspParameters Użyj klasy, aby wykonać następujące czynności:

  • Określ określony dostawca CSP, przekazując typ dostawcy do ProviderType właściwości lub ProviderName . Można również określić dostawcę usług kryptograficznych przy użyciu przeciążenia konstruktora.

  • Utwórz kontener kluczy, w którym można przechowywać klucze kryptograficzne. Kontenery kluczy zapewniają najbezpieczniejszy sposób utrwalania kluczy kryptograficznych i zabezpieczania ich przed złośliwymi firmami trzecimi. Aby uzyskać więcej informacji na temat tworzenia kontenerów kluczy, zobacz Jak przechowywać klucze asymetryczne w kontenerze kluczy.

  • Określ, czy utworzyć klucz sygnatury asymetrycznej, czy asymetryczny klucz wymiany przy użyciu KeyNumber właściwości .

Konstruktory

CspParameters()

Inicjuje nowe wystąpienie klasy CspParameters.

CspParameters(Int32)

Inicjuje CspParameters nowe wystąpienie klasy przy użyciu określonego kodu typu dostawcy.

CspParameters(Int32, String)

Inicjuje CspParameters nowe wystąpienie klasy z określonym kodem typu dostawcy i nazwą.

CspParameters(Int32, String, String)

Inicjuje CspParameters nowe wystąpienie klasy o określonym kodzie i nazwie typu dostawcy oraz określoną nazwę kontenera.

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

Inicjuje nowe wystąpienie CspParameters klasy przy użyciu typu dostawcy, nazwy dostawcy, nazwy kontenera, informacji o dostępie i uchwytu do niezarządzanego hasła karty inteligentnej.

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

Inicjuje nowe wystąpienie CspParameters klasy przy użyciu typu dostawcy, nazwy dostawcy, nazwy kontenera, informacji o dostępie i hasła skojarzonego z kluczem karty inteligentnej.

Pola

KeyContainerName

Reprezentuje nazwę kontenera klucza dla elementu CspParameters.

KeyNumber

Określa, czy klucz asymetryczny jest tworzony jako klucz podpisu, czy klucz wymiany.

ProviderName

Reprezentuje nazwę dostawcy dla elementu CspParameters.

ProviderType

Reprezentuje kod typu dostawcy dla elementu CspParameters.

Właściwości

CryptoKeySecurity

Pobiera lub ustawia CryptoKeySecurity obiekt reprezentujący prawa dostępu i reguły inspekcji dla kontenera.

Flags

Reprezentuje flagi, CspParameters które modyfikują zachowanie dostawcy usług kryptograficznych (CSP).

KeyPassword

Pobiera lub ustawia hasło skojarzone z kluczem karty inteligentnej.

ParentWindowHandle

Pobiera lub ustawia uchwyt do niezarządzanego okna nadrzędnego dla okna dialogowego hasła karty inteligentnej.

Metody

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetType()

Type Pobiera bieżące wystąpienie.

(Odziedziczone po Object)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Dotyczy

Zobacz też