Export (0) Print
Expand All

RSAOAEPKeyExchangeDeformatter.DecryptKeyExchange Method

Extracts secret information from the encrypted key exchange data.

Namespace:  System.Security.Cryptography
Assembly:  mscorlib (in mscorlib.dll)

Public Overrides Function DecryptKeyExchange ( _
	rgbData As Byte() _
) As Byte()


Type: System.Byte()

The key exchange data within which the secret information is hidden.

Return Value

Type: System.Byte()
The secret information derived from the key exchange data.


The key exchange data verification has failed.


The key is missing.

You must specify a key before calling this method.

The following example shows how to use the DecryptKeyExchange method to recreate an exchange key from a message sender. This code example is part of a larger example provided for the RSAPKCS1KeyExchangeDeformatter class.

Public Sub Receive(ByVal iv() As Byte, ByVal encryptedSessionKey() As Byte, ByVal encryptedMessage() As Byte)

    Using aes = New AesCryptoServiceProvider()

        aes.IV = iv

        ' Decrypt the session key 
        Dim keyDeformatter As New RSAOAEPKeyExchangeDeformatter(rsaKey)
        aes.Key = keyDeformatter.DecryptKeyExchange(encryptedSessionKey)

        ' Decrypt the message 
        Using plaintext As New MemoryStream()
            Using cs As New CryptoStream(plaintext, aes.CreateDecryptor(), CryptoStreamMode.Write)
                    cs.Write(encryptedMessage, 0, encryptedMessage.Length)

                    Dim message As String = Encoding.UTF8.GetString(plaintext.ToArray())
            End Using 
        End Using 
    End Using 

End Sub 'Receive

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8

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.

© 2014 Microsoft