https://tools.ietf.org/html/rfc5869
public static HKDF HKDF(HashAlgorithmName algorithm, byte[] ikm, byte[] info, int outputLength = 0, byte[] salt = null)
hash
The resulting hash from the HKDF calculation
HKDF takes 5 parameters:
- A
HashAlgorithmName
algorithm as defined from https://docs.microsoft.com/en-us/dotnet/core/api/system.security.cryptography.hashalgorithmname.HashAlgorithmName.HmacMd5 HashAlgorithmName.HmacSha1 HashAlgorithmName.HmacSha256 HashAlgorithmName.HmacSha384 HashAlgorithmName.HmacSha512
- The initial keying material
ikm
represented in bytes. - The additional authentication information
info
. - A byte
salt
. - The desired
outputLength
represented as an integer. If0
is set, theoutputLength
will be set to the algorithm length.
// This is the hash algorithm to use
var algorithm = HashAlgorithmName.SHA256;
// ikm, info, and salt can be variable length - for an example we're just going to generate some random bytes
var rng = new Random();
var ikm = new byte[32];
var salt = new byte[32];
var info = new byte[4];
rng.NextBytes(ikm);
rng.NextBytes(salt);
rng.NextBytes(info);
// Our HKDF can be calculated as follows.
var hkdf = new HKDF(algorithm, ikm, info, l, salt);
var hash = hkdf.hash;