This documentation is archived and is not being maintained.

RSAOAEPKeyExchangeFormatter.CreateKeyExchange Method (Byte[], Type)

Updated: March 2011

Creates the encrypted key exchange data from the specified input data.

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

public override byte[] CreateKeyExchange(
	byte[] rgbData,
	Type symAlgType


Type: System.Byte[]
The secret information to be passed in the key exchange.
Type: System.Type
This parameter is not used in the current version.

Return Value

Type: System.Byte[]
The encrypted key exchange data to be sent to the intended recipient.

This data can be interpreted only by the holder of the private key corresponding to the public key used to encrypt the data. This helps to ensure that only the intended recipient can access the secret information.

The following example shows how to use the RSAOAEPKeyExchangeFormatter.CreateKeyExchange(Byte[], Type) method to create an exchange key for a message recipient. This code example is part of a larger example provided for the RSAOAEPKeyExchangeFormatter class

private static void Send(RSA key, string secretMessage, out byte[] iv, out byte[] encryptedSessionKey, out byte[] encryptedMessage)
    using (Aes aes = new AesCryptoServiceProvider())
        iv = aes.IV;

        // Encrypt the session key
        RSAPKCS1KeyExchangeFormatter keyFormatter = new RSAPKCS1KeyExchangeFormatter(key);
        encryptedSessionKey = keyFormatter.CreateKeyExchange(aes.Key, typeof(Aes));

        // Encrypt the message
        using (MemoryStream ciphertext = new MemoryStream())
        using (CryptoStream cs = new CryptoStream(ciphertext, aes.CreateEncryptor(), CryptoStreamMode.Write))
            byte[] plaintextMessage = Encoding.UTF8.GetBytes(secretMessage);
            cs.Write(plaintextMessage, 0, plaintextMessage.Length);

            encryptedMessage = ciphertext.ToArray();

.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.




March 2011

Added a new example.

Customer feedback.