Usage
using OTPLib;TOTP
// Default: SHA1
string secretkey = "ADII2YLBLAAE5DLV36M7ZXXFIJT64753ZR3CSSWWVTRJE7WEWSDG3YVCKGYHSWL45SIJYRLX25UILRBFRTW35GUHJUBHCQXLWXEHG2I=";
TOTP totp = new TOTP(30, 6);
//TOTP totp = new TOTP(30, 6, OTPHashAlgorithm.SHA1);
string otpcode = totp.GenerateOTP(secretkey);
int timeleft = totp.GetRemainingTime();
Console.WriteLine("OTP code: {0}\r\nTimeleft: {1}", otpcode, timeleft.ToString());// SHA256
string secretkey = "JBSWY3DPEHPK3PXP";
TOTP totp = new TOTP(30, 6, OTPHashAlgorithm.SHA256);
string otpcode = totp.GenerateOTP(secretkey);
int timeleft = totp.GetRemainingTime();
Console.WriteLine("OTP code: {0}\r\nTimeleft: {1}", otpcode, timeleft.ToString());
// Set Hash Algorithm - SHA512
_totp.SetAlgorithm(OTPHashAlgorithm.SHA512);string secretkey = "JBSWY3DPEHPK3PXP";
TOTP totp = new TOTP(period, digits, algorithm);
bool verificationstatus = totp.Verify("otpcode", secretkey);HOTP
// Default: SHA1
string secretkey = "JVDSOVL2IZVGSWB4H5XG6WKGON7G4W2TLNKW27JL";
HOTP hotp = new HOTP(1000, 8, OTPHashAlgorithm.SHA1);
string otpcode = hotp.GenerateOTP(secretkey);string secretkey = "JVDSOVL2IZVGSWB4H5XG6WKGON7G4W2TLNKW27JL";
HOTP hotp = new HOTP(1000, 8, OTPHashAlgorithm.SHA256);
//hotp.SetAlgorithm(OTPHashAlgorithm.SHA256);
string otpcode = hotp.GenerateOTP(secretkey);
//string otpcode = hotp.GenerateOTP(secretkey, OTPHashAlgorithm.SHA256);string secretkey = "JBSWY3DPEHPK3PXP";
HOTP hotp = new HOTP(counter, digits, algorithm);
//hotp.SetCounter(652);
bool verificationstatus = hotp.Verify("otpcode", secretkey);
//bool verificationstatus = hotp.Verify("otpcode", secretkey, OTPHashAlgorithm.SHA256);// accountname: string, servicename: string, secretkey: Base32-key
string secretkey = "JVDSOVL2IZVGSWB4H5XG6WKGON7G4W2TLNKW27JL";
HOTP hotp = new HOTP(counter, digits, algorithm);
string otpurl = hotp.GetOTPUrl(accountname, servicename, secretkey);
string otpurl = hotp.GetOTPUrl("user@gmail.com", "Microsoft", secretkey, counter, digits, OTPHashAlgorithm.SHA1);Static Functions
Last updated