다음을 통해 공유


CspParameters 클래스

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

네임스페이스: System.Security.Cryptography
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
<ComVisibleAttribute(True)> _
Public NotInheritable Class CspParameters
‘사용 방법
Dim instance As CspParameters
[ComVisibleAttribute(true)] 
public sealed class CspParameters
[ComVisibleAttribute(true)] 
public ref class CspParameters sealed
/** @attribute ComVisibleAttribute(true) */ 
public final class CspParameters
ComVisibleAttribute(true) 
public final class CspParameters

설명

CspParameters 클래스는 비관리 Microsoft CAPI(Cryptography API)에서 Microsoft CSP(암호화 서비스 공급자)를 내부적으로 사용하는 관리되는 암호화 클래스로 전달할 수 있는 매개 변수를 나타냅니다. "CryptoServiceProvider"로 끝나는 이름의 클래스는 대응하는 CSP에 대한 코드 래퍼가 관리합니다.

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

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

  • 암호화 키를 저장할 수 있는 키 컨테이너를 만듭니다. 키 컨테이너를 사용하면 암호화 키를 보다 안전하게 유지하여 악의가 있는 사람이 접근하지 못하도록 할 수 있습니다. 키 컨테이너를 만드는 방법에 대한 자세한 내용은 방법: 키 컨테이너에 비대칭 키 저장을 참조하십시오.

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

항목 위치
방법: 키 컨테이너에 비대칭 키 저장 .NET Framework: Security
방법: 비대칭 키를 사용하여 XML 요소 해독 .NET Framework: Security
방법: 비대칭 키를 사용하여 XML 요소 암호화 .NET Framework: Security
방법: 키 컨테이너에 비대칭 키 저장 .NET Framework: 보안
방법: 비대칭 키를 사용하여 XML 요소 암호화 .NET Framework: 보안
방법: 비대칭 키를 사용하여 XML 요소 해독 .NET Framework: 보안

예제

다음 코드 예제에서는 CspParameters 클래스를 사용하여 키 컨테이너를 만들고 키를 컨테이너에 저장합니다.

Imports System
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 'Main
End Class 'StoreKey
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));
    }
}
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 ) );
}
import System.*;
import System.IO.*;
import System.Security.Cryptography.*;

public class StoreKey
{
    public static void main(String[] args)
    {
        // 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));
    } //main
} //StoreKey

다음 코드 예제에서는 CspParameters 클래스를 사용하여 스마트 카드 암호화 서비스 공급자를 선택합니다. 그런 다음 스마트 카드를 사용하여 데이터에 서명하고 확인합니다.

Imports System
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, "SHA1")

        Console.WriteLine("Signature : " + BitConverter.ToString(sig))

        ' Verify the data using the Smart Card CryptoGraphic Provider.
        Dim verified As Boolean = rsa.VerifyData(data, "SHA1", sig)

        Console.WriteLine("Verified")

    End Sub

End Module
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, "SHA1");

            Console.WriteLine("Signature    : " + BitConverter.ToString(sig));

            // Verify the data using the Smart Card CryptoGraphic Provider.
            bool verified = rsa.VerifyData(data, "SHA1", sig);

            Console.WriteLine("Verified     : " + verified);

        }
    }
}
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"SHA1" );
   Console::WriteLine( L"Signature  : {0}", BitConverter::ToString( sig ) );
   
   // Verify the data using the Smart Card CryptoGraphic Provider.
   bool verified = rsa->VerifyData( data, L"SHA1", sig );
   Console::WriteLine( L"Verified       : {0}", verified );
}

상속 계층 구조

System.Object
  System.Security.Cryptography.CspParameters

스레드로부터의 안전성

이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0에서 지원

참고 항목

참조

CspParameters 멤버
System.Security.Cryptography 네임스페이스

기타 리소스

암호화 서비스