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. Confused by QPasswordDigestor::deriveKeyPbkdf2 when trying to replicate Crypto-JS derived keys
Forum Updated to NodeBB v4.3 + New Features

Confused by QPasswordDigestor::deriveKeyPbkdf2 when trying to replicate Crypto-JS derived keys

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 255 Views
  • 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.
  • T Offline
    T Offline
    TiagoSD
    wrote on last edited by
    #1

    Hello, I am developing a Qt application that has to access a system where the apsswords were stored with Crypto-js derived hashes from the form :

    Crypto.PBKDF2('water', 'saltsaltsalt' ,{keySize:8, iterations:10000}).toString()
    
    on this fake data case resulting: 04b72ee92a8850bfdbe7cf801348a6701d11931702dcecad52f0b3351bedd01c
    
    
    
    

    I am trying to replicate the same password hashing with QT using:

    auto iterations = 10000;
        auto keyLen = 8;
        auto res = QPasswordDigestor::deriveKeyPbkdf2(QCryptographicHash::Algorithm::Sha1,
                                                      QString("water").toUtf8(),
                                                      QString("saltsaltsalt").toUtf8(),
                                   iterations,keyLen);
        qDebug()<<res;
    
        auto result = res.toBase64();
    

    but QT implementation returns me "BLcu6SqIUL8="

    That is not even the same length of the derived key. I think the algorithm should be standard and I could expect the same results but they are nowhere alike.

    Does anyone had any experience on trying to replicate Crypto-JS derived keys using QT implementation that could point me what I am missing?

    Christian EhrlicherC 1 Reply Last reply
    0
    • T TiagoSD

      Hello, I am developing a Qt application that has to access a system where the apsswords were stored with Crypto-js derived hashes from the form :

      Crypto.PBKDF2('water', 'saltsaltsalt' ,{keySize:8, iterations:10000}).toString()
      
      on this fake data case resulting: 04b72ee92a8850bfdbe7cf801348a6701d11931702dcecad52f0b3351bedd01c
      
      
      
      

      I am trying to replicate the same password hashing with QT using:

      auto iterations = 10000;
          auto keyLen = 8;
          auto res = QPasswordDigestor::deriveKeyPbkdf2(QCryptographicHash::Algorithm::Sha1,
                                                        QString("water").toUtf8(),
                                                        QString("saltsaltsalt").toUtf8(),
                                     iterations,keyLen);
          qDebug()<<res;
      
          auto result = res.toBase64();
      

      but QT implementation returns me "BLcu6SqIUL8="

      That is not even the same length of the derived key. I think the algorithm should be standard and I could expect the same results but they are nowhere alike.

      Does anyone had any experience on trying to replicate Crypto-JS derived keys using QT implementation that could point me what I am missing?

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Looks fine for me:

      See the documentation: "The function takes the data and salt, and then hashes it repeatedly for iterations iterations using the specified hash algorithm. If the resulting hash is longer than dkLen then it is truncated before it is returned."

      auto key1 = QByteArray::fromHex("04b72ee92a8850bfdbe7cf801348a6701d11931702dcecad52f0b3351bedd01c");
      auto key2 = QByteArray::fromBase64("BLcu6SqIUL8=");
      auto key2Hex = key2 .toHex(); // --> 04b72ee92a8850bf = 8 bytes
      

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      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