AsymmetricKeyExchangeDeformatter AsymmetricKeyExchangeDeformatter AsymmetricKeyExchangeDeformatter AsymmetricKeyExchangeDeformatter Class

Définition

Représente la classe de base dont dérivent tous les déformateurs d’échange de clés asymétriques.Represents the base class from which all asymmetric key exchange deformatters derive.

public ref class AsymmetricKeyExchangeDeformatter abstract
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class AsymmetricKeyExchangeDeformatter
type AsymmetricKeyExchangeDeformatter = class
Public MustInherit Class AsymmetricKeyExchangeDeformatter
Héritage
AsymmetricKeyExchangeDeformatterAsymmetricKeyExchangeDeformatterAsymmetricKeyExchangeDeformatterAsymmetricKeyExchangeDeformatter
Dérivé
Attributs

Exemples

L’exemple suivant montre comment étendre le AsymmetricKeyExchangeDeformatter classe.The following example demonstrates how to extend the AsymmetricKeyExchangeDeformatter class.

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 RSACryptoServiceProvider 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 RSACryptoServiceProvider)
                {
                    RSACryptoServiceProvider serviceProvder =
                        (RSACryptoServiceProvider)rsaKey;

                    decryptedBytes = serviceProvder.Decrypt(rgbData, true);
                }
                // 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
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 RSACryptoServiceProvider 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 RSACryptoServiceProvider) Then
                    Dim rsaProvider As RSACryptoServiceProvider
                    rsaProvider = CType(rsaKey, RSACryptoServiceProvider)

                    decryptedBytes = rsaProvider.Decrypt(rgbData, True)
                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.

Remarques

Les déformateurs d’échange de clés asymétriques déchiffrement les données de l’échange de clés.Asymmetric key exchange deformatters decrypt key exchange data.

Échange de clés permet à un expéditeur de créer des informations confidentielles, telles que des données aléatoires qui peuvent être utilisées en tant que clé dans un algorithme de chiffrement symétrique et utilisent le chiffrement pour l’envoyer au destinataire prévu.Key exchange allows a sender to create secret information, such as random data that can be used as a key in a symmetric encryption algorithm, and use encryption to send it to the intended recipient.

Attention

Il est vivement recommandé de ne pas créer votre propre méthode d’échange de clés à partir de la fonctionnalité de base fournie car de nombreux détails de l’opération doivent être effectuées avec soin afin que l’échange de clés réussir.It is highly recommended that you not attempt to create your own key exchange method from the basic functionality provided, because many details of the operation must be performed carefully in order for the key exchange to be successful.

Constructeurs

AsymmetricKeyExchangeDeformatter() AsymmetricKeyExchangeDeformatter() AsymmetricKeyExchangeDeformatter() AsymmetricKeyExchangeDeformatter()

Initialise une nouvelle instance de AsymmetricKeyExchangeDeformatter.Initializes a new instance of AsymmetricKeyExchangeDeformatter.

Propriétés

Parameters Parameters Parameters Parameters

En cas de substitution dans une classe dérivée, obtient ou définit les paramètres pour l’échange de clés asymétriques.When overridden in a derived class, gets or sets the parameters for the asymmetric key exchange.

Méthodes

DecryptKeyExchange(Byte[]) DecryptKeyExchange(Byte[]) DecryptKeyExchange(Byte[]) DecryptKeyExchange(Byte[])

En cas de substitution dans une classe dérivée, extrait des informations confidentielles à partir des données d’échange de clés chiffrées.When overridden in a derived class, extracts secret information from the encrypted key exchange data.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Détermine si l'objet spécifié est identique à l'objet actuel.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Fait office de fonction de hachage par défaut.Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Obtient le Type de l'instance actuelle.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Crée une copie superficielle de l'objet Object actuel.Creates a shallow copy of the current Object.

(Inherited from Object)
SetKey(AsymmetricAlgorithm) SetKey(AsymmetricAlgorithm) SetKey(AsymmetricAlgorithm) SetKey(AsymmetricAlgorithm)

En cas de substitution dans une classe dérivée, définit la clé privée à utiliser pour déchiffrer les informations confidentielles.When overridden in a derived class, sets the private key to use for decrypting the secret information.

ToString() ToString() ToString() ToString()

Retourne une chaîne qui représente l'objet actuel.Returns a string that represents the current object.

(Inherited from Object)

S’applique à