RSAOAEPKeyExchangeDeformatter.DecryptKeyExchange(Byte[]) メソッド

定義

暗号化されたキー交換データから機密情報を抽出します。Extracts secret information from the encrypted key exchange data.

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

パラメーター

rgbData
Byte[]

機密情報が非表示にされるキー交換データ。The key exchange data within which the secret information is hidden.

戻り値

Byte[]

キー交換データから派生する機密情報。The secret information derived from the key exchange data.

例外

キー交換データの検証に失敗しました。The key exchange data verification has failed.

キーがありません。The key is missing.

次の例では、DecryptKeyExchange メソッドを使用して、メッセージの送信者から交換キーを再作成する方法を示します。The following example shows how to use the DecryptKeyExchange method to recreate an exchange key from a message sender. このコード例は、RSAPKCS1KeyExchangeDeformatter クラス用に用意されている大規模な例の一部です。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
        RSAOAEPKeyExchangeDeformatter keyDeformatter = new RSAOAEPKeyExchangeDeformatter(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);
        }
    }
}
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)
                    cs.Close()

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

End Sub

注釈

このメソッドを呼び出す前に、キーを指定する必要があります。You must specify a key before calling this method.

適用対象

こちらもご覧ください