Rediger

Del via


AsymmetricKeyExchangeDeformatter.SetKey(AsymmetricAlgorithm) Method

Definition

When overridden in a derived class, sets the private key to use for decrypting the secret information.

public:
 abstract void SetKey(System::Security::Cryptography::AsymmetricAlgorithm ^ key);
public abstract void SetKey (System.Security.Cryptography.AsymmetricAlgorithm key);
abstract member SetKey : System.Security.Cryptography.AsymmetricAlgorithm -> unit
Public MustOverride Sub SetKey (key As AsymmetricAlgorithm)

Parameters

key
AsymmetricAlgorithm

The instance of the implementation of AsymmetricAlgorithm that holds the private key.

Examples

The following code example demonstrates how to override the SetKey to set the public key for encryption operations. This code example is part of a larger example provided for the AsymmetricKeyExchangeDeformatter class.

public override void SetKey(AsymmetricAlgorithm key)
{
    if (key != null)
    {
        _rsaKey = (RSA)key;
    }
    else
    {
        throw new ArgumentNullException(nameof(key));
    }
}
Public Overrides Sub SetKey(ByVal key As AsymmetricAlgorithm)
    If (Not key Is Nothing) Then
        rsaKey = CType(key, RSA)
    Else
        Throw New ArgumentNullException("key")
    End If
End Sub

Remarks

You must set a key before calling a DecryptKeyExchange implementation.

Applies to

See also