TrimSignature(byte[] buf) { return(BufArray.SubArray( buf, Hmac512.SignatureByteLength, buf.Length - Hmac512.SignatureByteLength )); }
ComputeSignature(byte[] key, byte[] buf) { using (HMACSHA512 hmac = new HMACSHA512(key)) { byte[] signature = hmac.ComputeHash(buf); BufArray.Wipe0(hmac.Key); // wipe key? return(signature); } }
VerifyTrim(byte[] key, byte[] buf) { if (!Hmac512.Verify(key, buf)) { return(null); } return(BufArray.SubArray( buf, Hmac512.SignatureByteLength, buf.Length - Hmac512.SignatureByteLength )); }
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); } }
SignPrepend(byte[] key, byte[] buf) { if (buf.Length < 1) { throw new Exception("Input buffer's length is too small."); } byte[] signature = ComputeSignature(key, buf); byte[] signed_data = BufArray.Combine(signature, buf); return(signed_data); //using (HMACSHA512 hmac = new HMACSHA512(key)) //{ // byte[] signature = hmac.ComputeHash(buf); // BufArray.Wipe0(hmac.Key); // byte[] signed_data = BufArray.Combine(signature, buf); // return signed_data; //} }