Bagikan melalui


RSAPKCS1KeyExchangeDeformatter.DecryptKeyExchange(Byte[]) Metode

Definisi

Mengekstrak informasi rahasia dari data pertukaran kunci terenkripsi.

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

Parameter

rgbIn
Byte[]

Data pertukaran kunci di mana informasi rahasia disembunyikan.

Mengembalikan

Byte[]

Informasi rahasia yang berasal dari data pertukaran kunci.

Pengecualian

Contoh

Contoh berikut menunjukkan cara menggunakan DecryptKeyExchange metode untuk membuat ulang kunci pertukaran dari pengirim pesan. Contoh kode ini adalah bagian dari contoh yang lebih besar yang disediakan untuk RSAPKCS1KeyExchangeDeformatter kelas .

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);
        }
    }
}
Public Sub Receive(ByVal iv() As Byte, ByVal encryptedSessionKey() As Byte, ByVal encryptedMessage() As Byte)

    Dim aes = New AesCryptoServiceProvider()
    Try
        aes.IV = iv

        ' Decrypt the session key
        Dim keyDeformatter As New RSAPKCS1KeyExchangeDeformatter(rsaKey)
        aes.Key = keyDeformatter.DecryptKeyExchange(encryptedSessionKey)

        ' Decrypt the message
        Dim plaintext As New MemoryStream()
        Try
            Dim cs As New CryptoStream(plaintext, aes.CreateDecryptor(), CryptoStreamMode.Write)
            Try
                cs.Write(encryptedMessage, 0, encryptedMessage.Length)
                cs.Close()

                Dim message As String = Encoding.UTF8.GetString(plaintext.ToArray())
                Console.WriteLine(message)
            Finally
                cs.Dispose()
            End Try
        Finally
            plaintext.Dispose()
        End Try
    Finally
        aes.Dispose()
    End Try

End Sub

Keterangan

Anda harus menentukan kunci sebelum memanggil metode ini.

Berlaku untuk

Lihat juga