Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. HMAC-SHA256 with Qt 4.8/Symbian / Convert QString to unsigned char[]
Forum Updated to NodeBB v4.3 + New Features

HMAC-SHA256 with Qt 4.8/Symbian / Convert QString to unsigned char[]

Scheduled Pinned Locked Moved Mobile and Embedded
2 Posts 2 Posters 2.8k 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
    schumi1331
    wrote on last edited by
    #1

    Hello everyone,

    for a Symbian app I'm required to create a HMAC-SHA256 hash from a QString. As Symbian doesn't support anything after Qt 4.8, I can't used the available Crypto libraries with SHA256 support that were added in Qt 5.1. So I found the following method (str is a QString):

    @QByteArray array = str.toUtf8();
    unsigned char iv[array.size()+1];
    for (int i=0; i<array.size(); i++) iv[i] = (unsigned char)array.at(i);

    unsigned char key[] = "testkey";

    unsigned char out[EVP_MAX_MD_SIZE];
    unsigned int outlen;

    ERR_clear_error();
    if (!HMAC(EVP_sha256(),key,sizeof(key)-1,iv,sizeof(iv)-1,out,&outlen)) return 0;
    QByteArray ret((char*)out);
    ret = ret.toBase64();
    return ret;@

    The hash creation (basics from here: http://www.opensource.apple.com/source/OpenSSL098/OpenSSL098-27/src/fips/fips_test_suite.c) works, when I'm passing an unsigned char[] as 'iv' directly (see the link). But when I'm creating an unsigned char[] from a QString it works to 90%. An example hash created with the method with QString to char[] ends with "zswEVA=". I've used various online tools to check how the hash should look like and it's "zs=". The whole hash up to this point is exactly the same at both versions, so I have to have an error when creating the char[] I think. Anyone knows what's wrong here?

    Best Regards,
    Sebastian

    1 Reply Last reply
    0
    • L Offline
      L Offline
      leon.anavi
      wrote on last edited by
      #2

      Please have a look at the "Symbian Cryptography APIs":http://developer.nokia.com/community/wiki/Archived:Symbian_Cryptography_APIs. May be you can find an implementation of the algorithm there. This an old Symbian C++ library for devices that nowadays we call ancient. You can combine the library and Symbian C++ code with Qt 4.8 or Qt 4.7 inside you application.

      http://anavi.org/

      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