CspParameters 클래스

정의

암호화 계산을 수행하는 CSP(암호화 서비스 공급자)에 전달된 매개 변수가 들어 있습니다. 이 클래스는 상속될 수 없습니다.

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
상속
CspParameters
특성

예제

다음 코드 예제에서는 클래스를 사용 하 여 키 컨테이너를 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 사용하여 스마트 카드 암호화 서비스 공급자를 선택합니다. 그런 다음 스마트 카드 사용하여 데이터에 서명하고 확인합니다.

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 관리되지 않는 CAPI(Microsoft Cryptography API)에서 내부적으로 Microsoft CSP(암호화 서비스 공급자)를 사용하는 관리형 암호화 클래스에 전달할 수 있는 매개 변수를 나타냅니다. 이름이 "CryptoServiceProvider"로 끝나는 클래스는 해당 CSP에 대한 관리 코드 래퍼입니다.

클래스를 CspParameters 사용하여 다음을 수행합니다.

  • 공급자 형식을 또는 ProviderName 속성에 전달하여 특정 CSP를 ProviderType 지정합니다. 생성자의 오버로드를 사용하여 CSP를 지정할 수도 있습니다.

  • 암호화 키를 저장할 수 있는 키 컨테이너를 만듭니다. 키 컨테이너는 암호화 키를 유지하고 악의적인 타사로부터 비밀을 유지하는 가장 안전한 방법을 제공합니다. 키 컨테이너를 만드는 방법에 대한 자세한 내용은 방법: 키 컨테이너에 비대칭 키 저장을 참조하세요.

  • 속성을 사용하여 KeyNumber 비대칭 서명 키 또는 비대칭 교환 키를 만들지 여부를 지정합니다.

생성자

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 클래스의 새 인스턴스를 초기화합니다.

필드

KeyContainerName

CspParameters에 대한 키 컨테이너 이름을 나타냅니다.

KeyNumber

비대칭 키를 서명 키 또는 교환 키로 만들지 여부를 지정합니다.

ProviderName

CspParameters의 공급자 이름을 나타냅니다.

ProviderType

CspParameters의 공급자 형식 코드를 나타냅니다.

속성

CryptoKeySecurity

컨테이너에 대한 액세스 권한과 감사 규칙을 나타내는 CryptoKeySecurity 개체를 가져오거나 설정합니다.

Flags

CSP(암호화 서비스 공급자)의 동작을 수정하는 CspParameters 의 플래그를 나타냅니다.

KeyPassword

스마트 카드 키와 관련된 암호를 가져오거나 설정합니다.

ParentWindowHandle

스마트 카드 암호 대화 상자의 비관리 부모 창에 대한 핸들을 가져오거나 설정합니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보