Udostępnij za pośrednictwem


AesCryptoServiceProvider.CreateDecryptor Metoda

Definicja

Tworzy symetryczny obiekt odszyfrowywania AES.

Przeciążenia

CreateDecryptor()

Tworzy symetryczny obiekt odszyfrowywania AES przy użyciu bieżącego klucza i wektora inicjowania (IV).

CreateDecryptor(Byte[], Byte[])

Tworzy symetryczny obiekt odszyfrowywania AES przy użyciu określonego klucza i wektora inicjowania (IV).

CreateDecryptor()

Źródło:
AesCryptoServiceProvider.cs
Źródło:
AesCryptoServiceProvider.cs
Źródło:
AesCryptoServiceProvider.cs

Tworzy symetryczny obiekt odszyfrowywania AES przy użyciu bieżącego klucza i wektora inicjowania (IV).

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

Zwraca

Symetryczny obiekt odszyfrowywania AES.

Atrybuty

Wyjątki

Bieżący klucz jest nieprawidłowy lub brakuje go.

Dotyczy

CreateDecryptor(Byte[], Byte[])

Źródło:
AesCryptoServiceProvider.cs
Źródło:
AesCryptoServiceProvider.cs
Źródło:
AesCryptoServiceProvider.cs

Tworzy symetryczny obiekt odszyfrowywania AES przy użyciu określonego klucza i wektora inicjowania (IV).

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

Parametry

rgbKeykey
Byte[]

Klucz tajny do użycia dla algorytmu symetrycznego.

rgbIViv
Byte[]

Wektor inicjowania do użycia dla algorytmu symetrycznego.

Zwraca

Symetryczny obiekt odszyfrowywania AES.

Atrybuty

Wyjątki

key lub iv ma wartość null.

Nazwa key jest niepoprawna.

Przykłady

W poniższym przykładzie pokazano, jak odszyfrować zaszyfrowany komunikat przy AesCryptoServiceProvider.CreateDecryptor użyciu metody . Ten przykład kodu jest częścią większego przykładu udostępnionego AesCryptoServiceProvider dla klasy .

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
let decryptStringFromBytes_Aes (cipherText : byte[], key : byte[], iv : byte[]) : string =

    // Check arguments.
    if (isNull cipherText || cipherText.Length <= 0) then nullArg "cipherText"
    if (isNull key || key.Length <= 0) then nullArg "key"
    if (isNull iv || iv.Length <= 0) then nullArg "iv"

    // Create an AesCryptoServiceProvider object
    // with the specified key and IV.
    use aesAlg = new AesCryptoServiceProvider()
    aesAlg.Key <- key
    aesAlg.IV <- iv

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

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

    // Read the decrypted bytes from the decrypting stream
    // and return the resulting string.
    srDecrypt.ReadToEnd()

Dotyczy