共用方式為


RSAOAEPKeyExchangeDeformatter.DecryptKeyExchange(Byte[]) 方法

定義

從加密的金鑰交換資料中擷取秘密資訊。

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[]

隱藏秘密資訊的金鑰交換資料。

傳回

Byte[]

從金鑰交換資料中衍生的秘密資訊。

例外狀況

金鑰交換資料驗證失敗。

範例

下列範例示範如何使用 DecryptKeyExchange 方法來重新建立郵件發件人的交換密鑰。 此程式代碼範例是針對 類別提供的較大範例的 RSAPKCS1KeyExchangeDeformatter 一部分。

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

備註

您必須在呼叫這個方法之前指定索引鍵。

適用於

另請參閱