c# - HMAC with custom HashAlgorithm -
there built in hmac's (hmacsha1 - hmacsha512 ...). possible create hmac custom hashalgorithm class?
i tried hmac.create("location")
threw nullreferenceexception
could there constructor new hmac(hashalgorithm)
?
this code hashalgorithm (fnv1 hash):
public class fnv1_32 : hashalgorithm { private const uint prime = 0x01000193; private const uint offsetbasis = 0x811c9dc5; private uint _hash; public fnv1_32() { this.initialize(); this.hashsizevalue = 32; } public override void initialize() { this._hash = offsetbasis; } protected override void hashcore(byte[] array, int ibstart, int cbsize) { (var = ibstart; < cbsize; i++) { this._hash *= prime; this._hash ^= array[i]; } } protected override byte[] hashfinal() { return bitconverter.getbytes(this._hash); } }
in .net framework can accomplish via like
public class hmacfnv1_32 : hmac { private const string fnv1cryptoconfigid = "fnv1_32"; static hmacfnv1_32() { cryptoconfig.addalgorithm(typeof(fnv1_32), fnv1cryptoconfigid); } public hmacfnv1_32(byte[] key) { hashname = fnv1cryptoconfigid; hashsizevalue = 32; key = key; } }
on .net core hmac implementation has been removed, of builtin hmac classes call system cryptography libraries perform hmac calculations. you'd need write hmac use custom digest .net core.
Comments
Post a Comment