Share via


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

備註

您必須先指定索引鍵,才能呼叫此方法的實作。

適用於

另請參閱