private static string ParentGuid = "3564a05b-1d18-4754-9352-a803b1e20554";
private static DateTime VerificationCodeCreated = DateTime.Now;
private static int VerificationCodeExpirationInSeconds = 300;
public static void Main()
var totpCode = GenerateTotpCode();
Console.WriteLine($"{nameof(totpCode)}: {totpCode}");
bool success = VerifyTotpCode(totpCode);
Console.WriteLine($"{nameof(success)}: {success}");
private static string GenerateTotpCode()
var totp = GetTotpForParent();
var totpCode = totp.ComputeTotp();
Console.WriteLine(totp.RemainingSeconds());
private static bool VerifyTotpCode(string totpCode)
var totp = GetTotpForParent();
bool success = totp.VerifyTotp(totpCode, out timeWindowUsed, new VerificationWindow(previous:1));
private static Totp GetTotpForParent()
var secretKey = Encoding.UTF8.GetBytes(ParentGuid);
var totp = new Totp(secretKey, mode: OtpHashMode.Sha512, step: VerificationCodeExpirationInSeconds);