ECDiffieHellman.DeriveKeyFromHash Method

Definition

Performs key derivation using a specified hash algorithm.

Overloads

DeriveKeyFromHash(ECDiffieHellmanPublicKey, HashAlgorithmName)

Performs key derivation using a specified hash algorithm.

DeriveKeyFromHash(ECDiffieHellmanPublicKey, HashAlgorithmName, Byte[], Byte[])

When implemented in a derived class, performs key derivation using a specified hash algorithm with optional prepended or appended data.

DeriveKeyFromHash(ECDiffieHellmanPublicKey, HashAlgorithmName)

Source:
ECDiffieHellman.cs
Source:
ECDiffieHellman.cs
Source:
ECDiffieHellman.cs

Performs key derivation using a specified hash algorithm.

C#
public byte[] DeriveKeyFromHash (System.Security.Cryptography.ECDiffieHellmanPublicKey otherPartyPublicKey, System.Security.Cryptography.HashAlgorithmName hashAlgorithm);

Parameters

otherPartyPublicKey
ECDiffieHellmanPublicKey

The other party's public key.

hashAlgorithm
HashAlgorithmName

The hash algorithm to use to derive the key material.

Returns

Byte[]

The hash of the shared secret.

Exceptions

The curve used by otherPartyPublicKey has a different size than the curve from this key.

-or-

The hashAlgorithm parameter does not specify a hash.

otherPartyPublicKey is null.

The curve used by otherPartyPublicKey is different than the curve from this key.

-or-

This instance represents only a public key.

Remarks

This overload calls the DeriveKeyFromHash method passing null as the prepend and append values.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.1

DeriveKeyFromHash(ECDiffieHellmanPublicKey, HashAlgorithmName, Byte[], Byte[])

Source:
ECDiffieHellman.cs
Source:
ECDiffieHellman.cs
Source:
ECDiffieHellman.cs

When implemented in a derived class, performs key derivation using a specified hash algorithm with optional prepended or appended data.

C#
public virtual byte[] DeriveKeyFromHash (System.Security.Cryptography.ECDiffieHellmanPublicKey otherPartyPublicKey, System.Security.Cryptography.HashAlgorithmName hashAlgorithm, byte[]? secretPrepend, byte[]? secretAppend);
C#
public virtual byte[] DeriveKeyFromHash (System.Security.Cryptography.ECDiffieHellmanPublicKey otherPartyPublicKey, System.Security.Cryptography.HashAlgorithmName hashAlgorithm, byte[] secretPrepend, byte[] secretAppend);

Parameters

otherPartyPublicKey
ECDiffieHellmanPublicKey

The other party's public key.

hashAlgorithm
HashAlgorithmName

The hash algorithm to use to derive the key material.

secretPrepend
Byte[]

A value to prepend to the derived secret before hashing.

secretAppend
Byte[]

A value to append to the derived secret before hashing.

Returns

Byte[]

The hash of the shared secret after prepending or appending data as requested.

Exceptions

A derived class must override this method.

The curve used by otherPartyPublicKey has a different size than the curve from this key.

-or-

The hashAlgorithm parameter does not specify a hash.

otherPartyPublicKey is null.

The curve used by otherPartyPublicKey is different than the curve from this key.

-or-

This instance represents only a public key.

Remarks

This method internally performs the Elliptic Curve Diffie-Hellman key agreement to produce the shared secret (z). The return value from this method is the result of HASH(secretPrepend || z || secretAppend) using the specified hash algorithm, where || signifies concatenation.

If the value of secretPrepend or secretAppend is null, they are treated as empty arrays.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.1