Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. TOTP | Help
Forum Updated to NodeBB v4.3 + New Features

TOTP | Help

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 2 Posters 2.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stef
    wrote on last edited by
    #1

    Hy, I want to create an application which will generate a TOTP code.
    (To connect to facebook,...).

    I found this code:

    QString hmacSha1(QByteArray key, QByteArray baseString)
    {
     int blockSize = 64; // HMAC-SHA-1 block size, defined in SHA-1 standard
     if (key.length() > blockSize) { // if key is longer than block size (64), reduce key length with SHA-1 compression
     key = QCryptographicHash::hash(key, QCryptographicHash::Sha1);
     }
    
    QByteArray innerPadding(blockSize, char(0x36)); // initialize inner padding with char "6"
     QByteArray outerPadding(blockSize, char(0x5c)); // initialize outer padding with char "quot;
     // ascii characters 0x36 ("6") and 0x5c ("quot;) are selected because they have large
     // Hamming distance (http://en.wikipedia.org/wiki/Hamming_distance)
    
    for (int i = 0; i < key.length(); i++) {
     innerPadding[i] = innerPadding[i] ^ key.at(i); // XOR operation between every byte in key and innerpadding, of key length
     outerPadding[i] = outerPadding[i] ^ key.at(i); // XOR operation between every byte in key and outerpadding, of key length
     }
    
    // result = hash ( outerPadding CONCAT hash ( innerPadding CONCAT baseString ) ).toBase64
     QByteArray total = outerPadding;
     QByteArray part = innerPadding;
     part.append(baseString);
     total.append(QCryptographicHash::hash(part, QCryptographicHash::Sha1));
     QByteArray hashed = QCryptographicHash::hash(total, QCryptographicHash::Sha1);
     return hashed.toBase64();
    }
    

    What can I do ?

    Thanks :)

    (sorry for my english, I'm french)

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Are you looking for something like QGoogleAuth ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Stef
        wrote on last edited by Stef
        #3

        Thanks for your help.
        I add the file to my project, but there's an error
        Do you want the projet ?

        mainwindow.obj:-1: erreur : LNK2019: unresolved external symbol "__declspec(dllimport) public: static class QString __cdecl QGoogleAuth::generatePin(class QByteArray)" (_imp?generatePin@QGoogleAuth@@SA?AVQString@@VQByteArray@@@Z) referenced in function "private: void __cdecl MainWindow::on_pushButton_clicked(void)" (?on_pushButton_clicked@MainWindow@@AEAAXXZ)

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Did you link your application to the library ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Stef
            wrote on last edited by
            #5

            I have to link which library ?
            (Sorry, I'm a novice)

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              The generated when you build the QGoogleAuth project.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Stef
                wrote on last edited by
                #7

                I add the ".lib" file, but the error still

                mainwindow.obj:-1: erreur : LNK2019: unresolved external symbol "__declspec(dllimport) public: static class QString __cdecl QGoogleAuth::generatePin(class QByteArray)" (_imp?generatePin@QGoogleAuth@@SA?AVQString@@VQByteArray@@@Z) referenced in function "private: void __cdecl MainWindow::on_pushButton_clicked(void)" (?on_pushButton_clicked@MainWindow@@AEAAXXZ)

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  How did you add that file ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    Stef
                    wrote on last edited by
                    #9

                    Right click on projet,
                    Add library
                    Extern library
                    I select the "qgoogleauth.lib" file :(

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      Stef
                      wrote on last edited by
                      #10

                      It's OK, I've found a solution.
                      I add all the file of the project, and I do not add library.
                      So, it build with my project.

                      Thank you very munch for your precious help :)

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved