2 out of 2 rated this helpful - Rate this topic

AesManaged.CreateDecryptor Method (Byte(), Byte())

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

Namespace:  System.Security.Cryptography
Assembly:  System.Core (in System.Core.dll)
Public Overrides Function CreateDecryptor ( _
	key As Byte(), _
	iv As Byte() _
) As ICryptoTransform


Type: System.Byte()

The secret key to use for the symmetric algorithm.

Type: System.Byte()

The initialization vector to use for the symmetric algorithm.

Return Value

Type: System.Security.Cryptography.ICryptoTransform
A symmetric decryptor object.

key or iv is Nothing.


key is invalid.

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.

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("Key")
        End If 
        ' Declare the string used to hold 
        ' the decrypted text. 
        Dim plaintext As String = Nothing 

        ' Create an AesManaged object 
        ' with the specified key and IV. 
        Using aesAlg As New AesManaged
            aesAlg.Key = Key
            aesAlg.IV = IV

            ' Create a decrytor 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

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft. All rights reserved.