예제 #1
0
        public static bool ValidateCode(byte[] securityToken, int code, string modifier = null)
        {
            bool flag = securityToken == null;

            if (flag)
            {
                throw new ArgumentNullException("securityToken");
            }
            ulong currentTimeStepNumber = Totp.GetCurrentTimeStepNumber();
            bool  result;

            using (HMACSHA1 hMACSHA = new HMACSHA1(securityToken))
            {
                for (int i = -2; i <= 2; i++)
                {
                    int  num   = Totp.ComputeTotp(hMACSHA, currentTimeStepNumber + (ulong)((long)i), modifier);
                    bool flag2 = num == code;
                    if (flag2)
                    {
                        result = true;
                        return(result);
                    }
                }
            }
            result = false;
            return(result);
        }
예제 #2
0
        public static int GenerateCode(byte[] securityToken, string modifier = null)
        {
            bool flag = securityToken == null;

            if (flag)
            {
                throw new ArgumentNullException("securityToken");
            }
            ulong currentTimeStepNumber = Totp.GetCurrentTimeStepNumber();
            int   result;

            using (HMACSHA1 hMACSHA = new HMACSHA1(securityToken))
            {
                result = Totp.ComputeTotp(hMACSHA, currentTimeStepNumber, modifier);
            }
            return(result);
        }