예제 #1
0
파일: Hmac.cs 프로젝트: glihmware/cryptool
    ComputeSignature(byte[] key, byte[] buf)
    {
        using (HMACSHA512 hmac = new HMACSHA512(key))
        {
            byte[] signature = hmac.ComputeHash(buf);

            BufArray.Wipe0(hmac.Key);
            // wipe key?
            return(signature);
        }
    }
예제 #2
0
파일: Hmac.cs 프로젝트: glihmware/cryptool
    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);
        }
    }