-
Notifications
You must be signed in to change notification settings - Fork 0
simpleotp.totp
Namespace: SimpleOTP
Represents a Time-based One-Time Password (TOTP) generator.
public class Totp : OtpInheritance Object → Otp → Totp
Attributes NullableContextAttribute, NullableAttribute
Gets or sets the time period (in seconds) for which each generated OTP is valid.
public int Period { get; set; }Remarks:
Also used to calculate the current counter value.
Gets or sets the secret key used for generating OTPs.
public OtpSecret Secret { get; set; }Gets or sets the algorithm used for generating OTP codes.
public OtpAlgorithm Algorithm { get; set; }Gets or sets the number of digits in the OTP code.
public int Digits { get; set; }Int32
Default: 6. Recommended: 6-8.
Initializes a new instance of the Totp class with the specified secret key.
public Totp(OtpSecret secret)secret OtpSecret
The secret key used for generating OTP codes.
Initializes a new instance of the Totp class with the specified secret key and number of OTP code digits.
public Totp(OtpSecret secret, int period)secret OtpSecret
The secret key used for generating OTP codes.
period Int32
The time period (in seconds) for which each generated OTP is valid.
Initializes a new instance of the Totp class with the specified secret key, number of OTP code digits, and time period.
public Totp(OtpSecret secret, int period, int digits)secret OtpSecret
The secret key used for generating OTP codes.
period Int32
The time period (in seconds) for which each generated OTP is valid.
digits Int32
The number of digits in the OTP code.
Initializes a new instance of the Totp class with the specified secret key, hash algorithm, and time period.
public Totp(OtpSecret secret, int period, OtpAlgorithm algorithm)secret OtpSecret
The secret key used for generating OTP codes.
period Int32
The time period (in seconds) for which each generated OTP is valid.
algorithm OtpAlgorithm
The algorithm used for generating OTP codes.
Initializes a new instance of the Totp class with the specified secret key, hash algorithm, number of digits, and time period.
public Totp(OtpSecret secret, int period, OtpAlgorithm algorithm, int digits)secret OtpSecret
The secret key used for generating OTP codes.
period Int32
The time period (in seconds) for which each generated OTP is valid.
algorithm OtpAlgorithm
The algorithm used for generating OTP codes.
digits Int32
The number of digits in the OTP code.
Generates an OTP based on the specified counter value.
public OtpCode Generate(long counter)counter Int64
The counter value to use for OTP generation.
OtpCode
An instance of OtpCode representing the generated OTP.
Generates an OTP based on the specified date and time.
public OtpCode Generate(DateTimeOffset date)date DateTimeOffset
The date and time to use for OTP generation.
OtpCode
An instance of OtpCode representing the generated OTP.
Gets the current counter value based on the current UTC time and the configured time period.
protected long GetCounter()Int64
The current counter value.
©2025 Eugene Fox. Licensed under MIT license