Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

RSAPKCS1KeyExchangeDeformatter.DecryptKeyExchange Method

Updated: March 2011

Extracts secret information from the encrypted key exchange data.

Namespace:  System.Security.Cryptography
Assembly:  mscorlib (in mscorlib.dll)
public override byte[] DecryptKeyExchange(
	byte[] rgbIn
)

Parameters

rgbIn
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.
ExceptionCondition
CryptographicUnexpectedOperationException

The key is missing.

You must specify a key before calling this method.

The following example shows how to use the DecryptKeyExchange(Byte[]) 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 void Receive(byte[] iv, byte[] encryptedSessionKey, byte[] encryptedMessage)
{

    using (Aes aes = new AesCryptoServiceProvider())
    {
        aes.IV = iv;

        // Decrypt the session key
        RSAPKCS1KeyExchangeDeformatter keyDeformatter = new RSAPKCS1KeyExchangeDeformatter(rsaKey);
        aes.Key = keyDeformatter.DecryptKeyExchange(encryptedSessionKey);

        // Decrypt the message
        using (MemoryStream plaintext = new MemoryStream())
        using (CryptoStream cs = new CryptoStream(plaintext, aes.CreateDecryptor(), CryptoStreamMode.Write))
        {
            cs.Write(encryptedMessage, 0, encryptedMessage.Length);
            cs.Close();

            string message = Encoding.UTF8.GetString(plaintext.ToArray());
            Console.WriteLine(message);
        }
    }
}


.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

Date

History

Reason

March 2011

Added an example.

Customer feedback.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.