RSAPKCS1KeyExchangeFormatter.CreateKeyExchange メソッド

定義

暗号化されたキー交換データを作成します。

オーバーロード

CreateKeyExchange(Byte[])

指定された入力データから暗号化したキー交換データを作成します。

CreateKeyExchange(Byte[], Type)

指定された入力データから暗号化したキー交換データを作成します。

CreateKeyExchange(Byte[])

ソース:
RSAPKCS1KeyExchangeFormatter.cs
ソース:
RSAPKCS1KeyExchangeFormatter.cs
ソース:
RSAPKCS1KeyExchangeFormatter.cs

指定された入力データから暗号化したキー交換データを作成します。

public:
 override cli::array <System::Byte> ^ CreateKeyExchange(cli::array <System::Byte> ^ rgbData);
public override byte[] CreateKeyExchange (byte[] rgbData);
override this.CreateKeyExchange : byte[] -> byte[]
Public Overrides Function CreateKeyExchange (rgbData As Byte()) As Byte()

パラメーター

rgbData
Byte[]

キー交換で渡される機密情報。

戻り値

Byte[]

目的の受信者に送信する暗号化されたキー交換データ。

例外

rgbData が大きすぎます。

注釈

このデータは、データの暗号化に使用される公開キーに対応する秘密キーの所有者のみが解釈できます。 これにより、目的の受信者のみがシークレット情報にアクセスできるようになります。

こちらもご覧ください

適用対象

CreateKeyExchange(Byte[], Type)

ソース:
RSAPKCS1KeyExchangeFormatter.cs
ソース:
RSAPKCS1KeyExchangeFormatter.cs
ソース:
RSAPKCS1KeyExchangeFormatter.cs

指定された入力データから暗号化したキー交換データを作成します。

public:
 override cli::array <System::Byte> ^ CreateKeyExchange(cli::array <System::Byte> ^ rgbData, Type ^ symAlgType);
public override byte[] CreateKeyExchange (byte[] rgbData, Type? symAlgType);
public override byte[] CreateKeyExchange (byte[] rgbData, Type symAlgType);
override this.CreateKeyExchange : byte[] * Type -> byte[]
Public Overrides Function CreateKeyExchange (rgbData As Byte(), symAlgType As Type) As Byte()

パラメーター

rgbData
Byte[]

キー交換で渡される機密情報。

symAlgType
Type

このパラメーターは、現在のバージョンでは使用されません。

戻り値

Byte[]

目的の受信者に送信する暗号化されたキー交換データ。

次の例は、 メソッドを RSAPKCS1KeyExchangeFormatter.CreateKeyExchange 使用してメッセージ受信者の交換キーを作成する方法を示しています。 このコード例は、RSAPKCS1KeyExchangeFormatter クラスのために提供されている大規模な例の一部です。

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);
            cs.Close();

            encryptedMessage = ciphertext.ToArray();
        }
    }
}
Private Shared Sub Send(ByVal key As RSA, ByVal secretMessage As String, ByRef iv() As Byte, ByRef encryptedSessionKey() As Byte, ByRef encryptedMessage() As Byte)
    Dim aes = New AesCryptoServiceProvider()
    Try
        iv = aes.IV

        ' Encrypt the session key
        Dim keyFormatter As New RSAPKCS1KeyExchangeFormatter(key)
        encryptedSessionKey = keyFormatter.CreateKeyExchange(aes.Key, GetType(Aes))

        ' Encrypt the message
        Dim ciphertext As New MemoryStream()
        Try
            Dim cs As New CryptoStream(ciphertext, aes.CreateEncryptor(), CryptoStreamMode.Write)
            Try
                Dim plaintextMessage As Byte() = Encoding.UTF8.GetBytes(secretMessage)
                cs.Write(plaintextMessage, 0, plaintextMessage.Length)
                cs.Close()

                encryptedMessage = ciphertext.ToArray()
            Finally
                cs.Dispose()
            End Try
        Finally
            ciphertext.Dispose()
        End Try
    Finally
        aes.Dispose()
    End Try

End Sub

注釈

このデータは、データの暗号化に使用される公開キーに対応する秘密キーの所有者のみが解釈できます。 これにより、目的の受信者のみがシークレット情報にアクセスできるようになります。

こちらもご覧ください

適用対象