コード例 #1
0
 public string GetCode()
 {
     if (_generator == null)
     {
         var bytes = Base32String.Instance.Decode(Key);
         _generator = new PasscodeGenerator(new HMACSHA1(bytes));
     }
     return(_generator.GenerateTimeoutCode());
 }
コード例 #2
0
 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();
 }
コード例 #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));
        }