Пример #1
0
        public static bool ValidateCode(byte[] securityToken, int code, string modifier = null)
        {
            var sectokenstring = Base32.ToBase32(securityToken);

            Console.Write(sectokenstring);

            if (securityToken == null)
            {
                throw new ArgumentNullException(nameof(securityToken));
            }

            // Allow a variance of no greater than 90 seconds in either direction
            var currentTimeStep = GetCurrentTimeStepNumber();

            using (var hashAlgorithm = new HMACSHA1(securityToken))
            {
                for (var i = -2; i <= 2; i++)
                {
                    var computedTotp = ComputeTotp(hashAlgorithm, (ulong)((long)currentTimeStep + i), modifier);
                    if (computedTotp == code)
                    {
                        return(true);
                    }
                }
            }

            // No match
            return(false);
        }
 public static string GenerateStandardSecret()
 {
     return(Base32.ToBase32(GenerateRandomKey(20)));
 }