AsymmetricKeyExchangeDeformatter.DecryptKeyExchange(Byte[]) Method

Definition

When overridden in a derived class, extracts secret information from the encrypted key exchange data.

C#
public abstract byte[] DecryptKeyExchange(byte[] rgb);

Parameters

rgb
Byte[]

The key exchange data within which the secret information is hidden.

Returns

Byte[]

The secret information derived from the key exchange data.

Examples

The following code example demonstrates how to override the DecryptKeyExchange method to create an encrypted key exchange for the specified input data. This code example is part of a larger example provided for the AsymmetricKeyExchangeDeformatter class.

C#
// 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;
}

Remarks

You must specify a key before calling an implementation of this method.

Applies to

Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

See also