0

I am trying to implement an OTP generator for Blackberry OS10. I already use the reference implementation on Android side, you can find it here:

So I would like to convert it to C++ / QNX code and I have some troubles with hexadecimal conversion...

In java:

private static byte[] hexStr2Bytes(String hex){
     // Adding one byte to get the right conversion
     // Values starting with "0" can be converted
     byte[] bArray = new BigInteger("10" + hex,16).toByteArray();

     // Copy all the REAL bytes, not the "first"
     byte[] ret = new byte[bArray.length - 1];
     for (int i = 0; i < ret.length; i++)
         ret[i] = bArray[i+1];
     return ret;
 }

In QNX:

QByteArray msg = QByteArray::fromHex(m.toLocal8Bit());

Problem is "m" start with '00' and so my final msg array is 0 length...

For example I try to encode the hex qstring:0000000002ca4e32

In blackberry: m=""

In Android: m="?M?"

So you can someone explain me how to deal with such a conversion ?

Thanks!

Genzotto
  • 1,954
  • 6
  • 26
  • 45

1 Answers1

0

What I would do is to translate your Java function to plain C++, i.e. not QT format. Then adapt data type to QT.

sergeyfo
  • 31
  • 1
  • 2