AsymmetricKeyExchangeDeformatter 클래스

정의

모든 비대칭 키 교환 디포맷터가 파생되는 기본 클래스를 나타냅니다.

public ref class AsymmetricKeyExchangeDeformatter abstract
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public abstract class AsymmetricKeyExchangeDeformatter
public abstract class AsymmetricKeyExchangeDeformatter
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class AsymmetricKeyExchangeDeformatter
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
type AsymmetricKeyExchangeDeformatter = class
type AsymmetricKeyExchangeDeformatter = class
[<System.Runtime.InteropServices.ComVisible(true)>]
type AsymmetricKeyExchangeDeformatter = class
Public MustInherit Class AsymmetricKeyExchangeDeformatter
상속
AsymmetricKeyExchangeDeformatter
파생
특성

예제

다음 예제에서는 클래스를 확장하는 방법을 보여 줍니다 AsymmetricKeyExchangeDeformatter .

using System;
using System.Security.Cryptography;

namespace Contoso
{
    public class ContosoDeformatter : AsymmetricKeyExchangeDeformatter
    {
        private RSA rsaKey;

        // Default constructor.
        public ContosoDeformatter(){}

        // Constructor with the public key to use for encryption.
        public ContosoDeformatter(AsymmetricAlgorithm key)
        {
            SetKey(key);
        }

        // Set the public key for encyption operations.
        public override void SetKey(AsymmetricAlgorithm key) {
            if (key != null)
            {
                rsaKey = (RSA)key;
            }
            else
            {
                throw new ArgumentNullException("key");
            }
        }

        // Disallow access to the parameters of the formatter.
        public override String Parameters 
        {
            get { return null; }
            set { ; }
        }

        // Create the encrypted key exchange data from the specified input
        // data. This method uses the RSA class only. To
        // support additional providers or provide custom decryption logic,
        // add logic to this member.
        public override byte[] DecryptKeyExchange(byte[] rgbData) {
            byte[] decryptedBytes = null;

            if (rsaKey != null)
            {
                if (rsaKey is RSA)
                {
                    RSA rsa = (RSA)rsaKey;

                    decryptedBytes = rsa.Decrypt(rgbData, RSAEncryptionPadding.OaepSHA1);
                }
                // Add custom decryption logic here.
            }
            else
            {
                throw new CryptographicUnexpectedOperationException(
                    "Cryptography_MissingKey");
            }

            return decryptedBytes;
        }
    }
}
//
// This code example produces the following output:
//
// Data to encrypt : Sample Contoso encryption application.
// Encrypted data: Khasdf-3248&$%23
// Data decrypted : Sample Contoso encryption application.
// 
// This sample completed successfully; press Enter to exit.
Imports System.Security.Cryptography

Namespace Contoso
    Public Class ContosoDeformatter
        Inherits AsymmetricKeyExchangeDeformatter

        Private rsaKey As RSA

        ' Default constructor.
        Public Sub New()

        End Sub

        ' Constructor with the public key to use for encryption.
        Public Sub New(ByVal key As AsymmetricAlgorithm)
            SetKey(key)
        End Sub

        ' Set the public key for encyption operations.
        Public Overrides Sub SetKey(ByVal key As AsymmetricAlgorithm)
            If (Not key Is Nothing) Then
                rsaKey = CType(key, RSA)
            Else
                Throw New ArgumentNullException("key")
            End If
        End Sub

        ' Disallow access to the parameters of the formatter.
        Public Overrides ReadOnly Property Parameters() As String
            Get
                Return Nothing
            End Get
            Set(ByVal Value As String)

            End Set
        End Property

        ' Create the encrypted key exchange data from the specified input
        ' data. This method uses the RSA class only. To
        ' support additional providers or provide custom decryption logic,
        ' add logic to this member.
        Public Overrides Function DecryptKeyExchange(
            ByVal rgbData() As Byte) As Byte()

            Dim decryptedBytes() As Byte

            If (Not rsaKey Is Nothing) Then
                If (TypeOf (rsaKey) Is RSA) Then
                    Dim rsa As RSA
                    rsa = CType(rsaKey, RSA)

                    decryptedBytes = rsa.Decrypt(rgbData, RSAEncryptionPadding.OaepSHA1)
                End If

                ' Add custom decryption logic here.

            Else
                Throw New CryptographicUnexpectedOperationException(
                    "Cryptography_MissingKey")
            End If

            Return decryptedBytes
        End Function

    End Class
End Namespace
'
' This code example produces the following output:
'
' Data to encrypt : Sample Contoso encryption application.
' Encrypted data: Kh34dfg-(*&834d+3
' Data decrypted : Sample Contoso encryption application.
' 
' This sample completed successfully; press Exit to continue.

설명

비대칭 키 교환 디포마터는 키 교환 데이터의 암호를 해독합니다.

키 교환을 사용하면 보낸 사람이 대칭 암호화 알고리즘에서 키로 사용할 수 있는 임의 데이터와 같은 비밀 정보를 만들고 암호화를 사용하여 의도한 받는 사람에게 보낼 수 있습니다.

주의

시도 하지 것 성공 하려면 키 교환에 대 한 순서 대로 작업의 많은 세부 정보를 신중 하 게 수행 해야 하기 때문에 제공 된 기본 기능에서 사용자 고유의 키 교환 메서드를 만드는 것이 좋습니다.

생성자

AsymmetricKeyExchangeDeformatter()

AsymmetricKeyExchangeDeformatter의 새 인스턴스를 초기화합니다.

속성

Parameters

파생 클래스에서 재정의된 경우 비대칭 키 교환에 대한 매개 변수를 가져오거나 설정합니다.

메서드

DecryptKeyExchange(Byte[])

파생 클래스에서 재정의된 경우 암호화된 키 교환 데이터에서 비밀 정보를 추출합니다.

Equals(Object)

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

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

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

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

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

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

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

(다음에서 상속됨 Object)
SetKey(AsymmetricAlgorithm)

파생 클래스에서 재정의된 경우 비밀 정보의 암호를 해독하는 데 사용할 프라이빗 키를 설정합니다.

ToString()

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

(다음에서 상속됨 Object)

적용 대상