Ejemplo n.º 1
0
 public string GetCode()
 {
     if (_generator == null)
     {
         var bytes = Base32String.Instance.Decode(Key);
         _generator = new PasscodeGenerator(new HMACSHA1(bytes));
     }
     return(_generator.GenerateTimeoutCode());
 }
 static void Main(string[] args)
 {
     Console.Write("Two step verification secret: ");
     string secret = Console.ReadLine();
     //Decode the secret given by Google
     byte[] secretBytes = Base32String.Instance.Decode(secret);
     PasscodeGenerator passGenenerator = new PasscodeGenerator(new HMACSHA1(secretBytes));
     string timeoutCode = passGenenerator.GenerateTimeoutCode();
     if (!passGenenerator.VerifyTimeoutCode(timeoutCode))
         Console.WriteLine("Timeout code couldn't be verified!");
     else
         Console.WriteLine("Timeout code: {0}", timeoutCode);
     Console.ReadLine();
 }
Ejemplo n.º 3
0
        public AuthKey(string name, string key)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException("name");
            }

            if (string.IsNullOrWhiteSpace(key))
            {
                throw new ArgumentNullException("key");
            }

            Name = name;
            Key  = key;

            var bytes = Base32String.Instance.Decode(key);

            _generator = new PasscodeGenerator(new HMACSHA1(bytes));
        }