語言

AsymmetricKeyExchangeDeformatter.DecryptKeyExchange(Byte[]) 方法

定義

當在派生類別中覆寫時,會從加密的金鑰交換資料中提取秘密資訊。

public:
 abstract cli::array <System::Byte> ^ DecryptKeyExchange(cli::array <System::Byte> ^ rgb);
public abstract byte[] DecryptKeyExchange(byte[] rgb);
abstract member DecryptKeyExchange : byte[] -> byte[]
Public MustOverride Function DecryptKeyExchange (rgb As Byte()) As Byte()

參數

rgb
Byte[]

密鑰交換資料,其中隱藏著秘密資訊。

傳回

Byte[]

這些秘密資訊來自金鑰交換資料。

範例

以下程式碼範例示範如何覆寫 DecryptKeyExchange 該方法,以建立指定輸入資料的加密金鑰交換。 此程式碼範例是本類別更大範例 AsymmetricKeyExchangeDeformatter 的一部分。

// Create the encrypted key exchange data from the specified input
// data. This method uses the RSA class only. To
// support additional providers or provide custom decryption logic,
// add logic to this member.
public override byte[] DecryptKeyExchange(byte[] rgbData)
{
    byte[] decryptedBytes = null;

    if (_rsaKey != null)
    {
        if (_rsaKey is RSA rsa)
        {
            decryptedBytes = rsa.Decrypt(rgbData, RSAEncryptionPadding.OaepSHA1);
        }
        // Add custom decryption logic here.
    }
    else
    {
        throw new CryptographicUnexpectedOperationException(
            "Cryptography_MissingKey");
    }

    return decryptedBytes;
}
' Create the encrypted key exchange data from the specified input
' data. This method uses the RSA class only. To
' support additional providers or provide custom decryption logic,
' add logic to this member.
Public Overrides Function DecryptKeyExchange(
    ByVal rgbData() As Byte) As Byte()

    Dim decryptedBytes() As Byte

    If (Not rsaKey Is Nothing) Then
        If (TypeOf (rsaKey) Is RSA) Then
            Dim rsa As RSA
            rsa = CType(rsaKey, RSA)

            decryptedBytes = rsa.Decrypt(rgbData, RSAEncryptionPadding.OaepSHA1)
        End If

        ' Add custom decryption logic here.

    Else
        Throw New CryptographicUnexpectedOperationException(
            "Cryptography_MissingKey")
    End If

    Return decryptedBytes
End Function

備註

你必須先指定一個金鑰,才能呼叫此方法的實作。

適用於

另請參閱