ComputeSignature(byte[] key, byte[] buf) { using (HMACSHA512 hmac = new HMACSHA512(key)) { byte[] signature = hmac.ComputeHash(buf); BufArray.Wipe0(hmac.Key); // wipe key? return(signature); } }
Verify(byte[] key, byte[] buf) { if (key == null) { throw new ArgumentException("Hmac key must not be null."); } if (buf == null | buf.Length < Hmac512.SignatureByteLength + 1) { throw new ArgumentException("Hmac input buffer's length is too short or null."); } using (HMACSHA512 hmac = new HMACSHA512(key)) { // Skip the prepended hmac signature. byte[] computedSignature = hmac.ComputeHash( buf, Hmac512.SignatureByteLength, buf.Length - Hmac512.SignatureByteLength ); bool ret; if (!BufArray.Compare( buf, 0, computedSignature, 0, Hmac512.SignatureByteLength) ) { ret = false; } else { ret = true; } BufArray.Wipe0(hmac.Key); return(ret); } }