public static AuthCode GenerateAuthCode(AuthKey key) { if (key.Type == AuthType.HOTP) return GenerateHOTP(key, key.Counter); return GenerateTOTP(key, DateTime.UtcNow); }
public static AuthCode GenerateTOTP(AuthKey key, DateTime dateTime) { long T = getTfromTime(dateTime, key.Period); var authCode = GenerateHOTP(key, T); authCode.Age = getAgeFromTime(dateTime, key.Period); return authCode; }
private static AuthCode GenerateHOTP(AuthKey key, long C) { byte[] Cbytes = getBytesFromLong(C); HMAC hmac = HMAC.Create("HMAC" + key.Algorithm); hmac.Key = key.Key; byte[] hash = hmac.ComputeHash(Cbytes); // put selected bytes into result int int offset = hash[hash.Length - 1] & 0xf; int binary = ((hash[offset] & 0x7f) << 24) | (hash[offset + 1] << 16) | (hash[offset + 2] << 8) | hash[offset + 3]; int otp = binary % DIGITS_POWER[key.NumDigits]; string totpString = Convert.ToString(otp); while (totpString.Length < key.NumDigits) totpString = "0" + totpString; return new AuthCode { Value = totpString }; }
public AuthorizerEntry(string uriString) { this.authKey = new AuthKey(uriString); initializeGuiElements(); UpdateCodeAsync(); }