AesCryptoServiceProvider.CreateDecryptor AesCryptoServiceProvider.CreateDecryptor AesCryptoServiceProvider.CreateDecryptor AesCryptoServiceProvider.CreateDecryptor Method

Definition

Erstellt ein symmetrisches AES-Entschlüsselungsobjekt.Creates a symmetric AES decryptor object.

Überlädt

CreateDecryptor() CreateDecryptor() CreateDecryptor() CreateDecryptor()

Erstellt ein symmetrisches AES-Entschlüsselungsobjekt mit dem aktuellen Schlüssel und Initialisierungsvektor (IV).Creates a symmetric AES decryptor object using the current key and initialization vector (IV).

CreateDecryptor(Byte[], Byte[]) CreateDecryptor(Byte[], Byte[]) CreateDecryptor(Byte[], Byte[]) CreateDecryptor(Byte[], Byte[])

Erstellt ein symmetrisches AES-Entschlüsselungsobjekt mit dem mit dem angegebenen Schlüssel und Initialisierungsvektor (IV).Creates a symmetric AES decryptor object using the specified key and initialization vector (IV).

CreateDecryptor() CreateDecryptor() CreateDecryptor() CreateDecryptor()

Erstellt ein symmetrisches AES-Entschlüsselungsobjekt mit dem aktuellen Schlüssel und Initialisierungsvektor (IV).Creates a symmetric AES decryptor object using the current key and initialization vector (IV).

public:
 override System::Security::Cryptography::ICryptoTransform ^ CreateDecryptor();
[System.Security.SecurityCritical]
public override System.Security.Cryptography.ICryptoTransform CreateDecryptor ();
override this.CreateDecryptor : unit -> System.Security.Cryptography.ICryptoTransform
Public Overrides Function CreateDecryptor () As ICryptoTransform

Gibt zurück

Ein symmetrisches AES-Entschlüsselungsobjekt.A symmetric AES decryptor object.

Ausnahmen

Der aktuelle Schlüssel ist ungültig oder fehlt.The current key is invalid or missing.

CreateDecryptor(Byte[], Byte[]) CreateDecryptor(Byte[], Byte[]) CreateDecryptor(Byte[], Byte[]) CreateDecryptor(Byte[], Byte[])

Erstellt ein symmetrisches AES-Entschlüsselungsobjekt mit dem mit dem angegebenen Schlüssel und Initialisierungsvektor (IV).Creates a symmetric AES decryptor object using the specified key and initialization vector (IV).

public:
 override System::Security::Cryptography::ICryptoTransform ^ CreateDecryptor(cli::array <System::Byte> ^ key, cli::array <System::Byte> ^ iv);
[System.Security.SecurityCritical]
public override System.Security.Cryptography.ICryptoTransform CreateDecryptor (byte[] key, byte[] iv);
override this.CreateDecryptor : byte[] * byte[] -> System.Security.Cryptography.ICryptoTransform
Public Overrides Function CreateDecryptor (key As Byte(), iv As Byte()) As ICryptoTransform

Parameter

rgbKey
Byte[]

Der geheime Schlüssel, der für den symmetrischen Algorithmus verwendet werden soll.The secret key to use for the symmetric algorithm.

rgbIV
Byte[]

Der Initialisierungsvektor, der für den symmetrischen Algorithmus verwendet werden soll.The initialization vector to use for the symmetric algorithm.

Gibt zurück

Ein symmetrisches AES-Entschlüsselungsobjekt.A symmetric AES decryptor object.

Ausnahmen

Beispiele

Das folgende Beispiel zeigt, wie Sie mit der AesCryptoServiceProvider.CreateDecryptor Methode, um eine verschlüsselte Nachricht zu entschlüsseln.The following example shows how to use the AesCryptoServiceProvider.CreateDecryptor method to decrypt an encrypted message. Dieses Codebeispiel ist Teil eines umfangreicheren Beispiels für die AesCryptoServiceProvider Klasse.This code example is part of a larger example provided for the AesCryptoServiceProvider class.

static string DecryptStringFromBytes_Aes(byte[] cipherText, byte[] Key, byte[] IV)
{
    // Check arguments.
    if (cipherText == null || cipherText.Length <= 0)
        throw new ArgumentNullException("cipherText");
    if (Key == null || Key.Length <= 0)
        throw new ArgumentNullException("Key");
    if (IV == null || IV.Length <= 0)
        throw new ArgumentNullException("IV");

    // Declare the string used to hold
    // the decrypted text.
    string plaintext = null;

    // Create an AesCryptoServiceProvider object
    // with the specified key and IV.
    using (AesCryptoServiceProvider aesAlg = new AesCryptoServiceProvider())
    {
        aesAlg.Key = Key;
        aesAlg.IV = IV;

        // Create a decryptor to perform the stream transform.
        ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);

        // Create the streams used for decryption.
        using (MemoryStream msDecrypt = new MemoryStream(cipherText))
        {
            using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
            {
                using (StreamReader srDecrypt = new StreamReader(csDecrypt))
                {

                    // Read the decrypted bytes from the decrypting stream
                    // and place them in a string.
                    plaintext = srDecrypt.ReadToEnd();
                }
            }
        }

    }

    return plaintext;

}
    Shared Function DecryptStringFromBytes_Aes(ByVal cipherText() As Byte,ByVal Key() As Byte, ByVal IV() As Byte) As String
        ' Check arguments.
        If cipherText Is Nothing OrElse cipherText.Length <= 0 Then
            Throw New ArgumentNullException("cipherText")
        End If
        If Key Is Nothing OrElse Key.Length <= 0 Then
            Throw New ArgumentNullException("Key")
        End If
        If IV Is Nothing OrElse IV.Length <= 0 Then
            Throw New ArgumentNullException("IV")
        End If
        ' Declare the string used to hold
        ' the decrypted text.
        Dim plaintext As String = Nothing

        ' Create an AesCryptoServiceProvider object
        ' with the specified key and IV.
        Using aesAlg As New AesCryptoServiceProvider()

            aesAlg.Key = Key
            aesAlg.IV = IV

            ' Create a decryptor to perform the stream transform.
            Dim decryptor As ICryptoTransform = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV)

            ' Create the streams used for decryption.
            Using msDecrypt As New MemoryStream(cipherText)

                Using csDecrypt As New CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)

                    Using srDecrypt As New StreamReader(csDecrypt)

                        ' Read the decrypted bytes from the decrypting stream
                        ' and place them in a string.
                        plaintext = srDecrypt.ReadToEnd()
                    End Using
                End Using
            End Using
        End Using
        Return plaintext

    End Function 'DecryptStringFromBytes_Aes 
End Class 'AesExample

Gilt für: