A C++17 based OTP header-only library for Windows.
Minimum OS requirement: Windows10. Because it uses BCryptHash
API.
Minimum OS requirement: Windows Vista. Because it uses Windows CNG APIs.
Code:
#include <tchar.h>
#include <windows.h>
#include <WinOTP.hpp>
#define OTP_SECRET TEXT("base32secret3232")
int _tmain(int argc, PTSTR argv[]) {
WinOTP::HOTP Hotp;
WinOTP::TOTP Totp;
Hotp.ImportSecretBase32(OTP_SECRET);
Totp.ImportSecretBase32(OTP_SECRET);
_tprintf_s(TEXT("Secret = %s\n"), OTP_SECRET);
_tprintf_s(TEXT("Hotp(0) = %s\n"), Hotp.GenerateCodeString(0).c_str());
_tprintf_s(TEXT("Hotp(1) = %s\n"), Hotp.GenerateCodeString(1).c_str());
_tprintf_s(TEXT("Hotp(1401) = %s\n"), Hotp.GenerateCodeString(1401).c_str());
_tprintf_s(TEXT("Totp = %s\n"), Totp.GenerateCodeString().c_str());
return 0;
}
Output:
Secret = base32secret3232
Hotp(0) = 260182
Hotp(1) = 055283
Hotp(1401) = 316439
Totp = 261656 # this one based on your time.