예제 #1
0
파일: Hmac.cs 프로젝트: glihmware/cryptool
 TrimSignature(byte[] buf)
 {
     return(BufArray.SubArray(
                buf,
                Hmac512.SignatureByteLength,
                buf.Length - Hmac512.SignatureByteLength
                ));
 }
예제 #2
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);
        }
    }
예제 #3
0
파일: Hmac.cs 프로젝트: glihmware/cryptool
    VerifyTrim(byte[] key, byte[] buf)
    {
        if (!Hmac512.Verify(key, buf))
        {
            return(null);
        }

        return(BufArray.SubArray(
                   buf,
                   Hmac512.SignatureByteLength,
                   buf.Length - Hmac512.SignatureByteLength
                   ));
    }
예제 #4
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);
        }
    }
예제 #5
0
파일: Hmac.cs 프로젝트: glihmware/cryptool
    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;
        //}
    }