public unsafe void Hkdf(string input) { var lines = input.Split('\n').Select(l => l.Trim().Split('=')).ToDictionary(val => val[0], val => val[1]); HashType hashType = (HashType)Enum.Parse(typeof(HashType), lines["Hash"], true); var ikm = StringToByteArray(lines["IKM"]); var salt = string.IsNullOrEmpty(lines["salt"]) ? new byte[0] : StringToByteArray(lines["salt"]); var info = string.IsNullOrEmpty(lines["info"]) ? new byte[0] : StringToByteArray(lines["info"]); var prk = StringToByteArray(lines["PRK"]); var okm = StringToByteArray(lines["OKM"]); var provider = new HashProvider(); var prkResult = new byte[provider.HashSize(hashType)]; var okmResult = new byte[okm.Length]; fixed(byte *iPtr = ikm) fixed(byte *sPtr = salt) fixed(byte *prPtr = prkResult) { HkdfFunctions.HkdfExtract(provider, hashType, sPtr, salt.Length, iPtr, ikm.Length, prPtr, prkResult.Length); HkdfFunctions.HkdfExpand(provider, hashType, prPtr, prkResult.Length, new Span <byte>(info), new Span <byte>(okmResult)); } Assert.Equal <byte>(prkResult, prk); for (int i = 0; i < okmResult.Length; i++) { Assert.Equal(okmResult[i], okm[i]); } }