Olvasás angol nyelven Szerkesztés

Megosztás a következőn keresztül:


AesManaged.CreateDecryptor Method

Definition

Creates a symmetric decryptor object.

Overloads

CreateDecryptor()

Creates a symmetric decryptor object using the current key and initialization vector (IV).

CreateDecryptor(Byte[], Byte[])

Creates a symmetric decryptor object using the specified key and initialization vector (IV).

CreateDecryptor()

Source:
AesManaged.cs
Source:
AesManaged.cs
Source:
AesManaged.cs

Creates a symmetric decryptor object using the current key and initialization vector (IV).

C#
public override System.Security.Cryptography.ICryptoTransform CreateDecryptor();

Returns

A symmetric decryptor object.

Applies to

.NET 10 és más verziók
Termék Verziók
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

CreateDecryptor(Byte[], Byte[])

Source:
AesManaged.cs
Source:
AesManaged.cs
Source:
AesManaged.cs

Creates a symmetric decryptor object using the specified key and initialization vector (IV).

C#
public override System.Security.Cryptography.ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[]? rgbIV);
C#
public override System.Security.Cryptography.ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[] rgbIV);
C#
public override System.Security.Cryptography.ICryptoTransform CreateDecryptor(byte[] key, byte[] iv);

Parameters

rgbKeykey
Byte[]

The secret key to use for the symmetric algorithm.

rgbIViv
Byte[]

The initialization vector to use for the symmetric algorithm.

Returns

A symmetric decryptor object.

Exceptions

key or iv is null.

key is invalid.

Examples

The following example shows how to use the AesManaged.CreateDecryptor method to decrypt an encrypted message. This code example is part of a larger example provided for the AesManaged class.

C#
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 AesManaged object
    // with the specified key and IV.
    using (AesManaged aesAlg = new AesManaged())
    {
        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;
}

Applies to

.NET 10 és más verziók
Termék Verziók
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1