admin管理员组

文章数量:1401940

I'm using Botan2 to implement a 2-factor-authentification. I cannot find any information which format Botan2 expects the secret key to be. If I just enter the same key as string I enter in the authenticator app (Google Authenticator in this case) I'm not getting the same 6-digit number as a result.

By trial-and-error I found that I get the same 6-digit number when I center in the Authenticator App AAAAAAAAAAAAAAAA and when I pass the string "0000000000000000" to Botan::SymmetricKey. But BBBBBBBBBBBBBBBB does not correspond to 1111111111111111.

As a minimal example I have this command line program which expects a 6-digit code as first cmd line parameter like ./totp-test.o 123456

#include <iostream>
#include <botan/otp.h>
#include <chrono>

using namespace std;

int main(int argc, char* argv[]) {
     // I have to enter AAAAAAAAAAAAAAAA in authenticator app to match the 6-digit number
    Botan::SymmetricKey key ("0000000000000000");
    Botan::TOTP totp (key);
    chrono::time_point now = chrono::time_point_cast<chrono::milliseconds>(
        chrono::system_clock::now()
    );
    
    cout<<"local totp: "<<totp.generate_totp (now)<<endl;
    
    int given_totp = atoi(argv[1]);
    cout<<"given totp: "<<given_totp<<endl;
    cout<<"verify: " <<totp.verify_totp (given_totp, now)<<endl;
    
    return 0;

I'm very sure all my clocks are synced.

本文标签: cBotan2 TOTP how to convert secretStack Overflow