0

I have a text representation of a encrypted buffer (via gcrypt) as follows:

(enc-val 
 (ecdh 
  (s #04FA304FE9E91BED21E3C5898796056CE4E590E12BC74D0219A185D2E0B9B49A7393F023415F3E1FFD22D5B0A134E03F84D5C5DF7C5326C51971CFB783A26F1636#)
  (e #0411C41FC2ECB6F6F482050C005B30F75E134FD8AEA1E45F687A9E995CCFFB14DDD8EA41462E41CAEBA2AA21CA8F70C67FF4AA6620E64BABA23CCA0088F292256D#)
  )
 )

I then convert this text string to a (uint_8) value array via the function data_from_string. The function is as follows:

size_t data_from_string(const char *str, uint8_t **data)
    {
        char tmp[3];
        size_t size, i;

        info("data_from_string");

        size = strlen(str) / 2;
        *data = (uint8_t *)malloc(size);
        if (*data == NULL)
            return 0;

        tmp[2] = '\0';
        for (i = 0; i < size; i++) {
            memcpy(tmp, str + (i * 2), 2);
            (*data)[i] = (uint8_t) strtol(tmp, NULL, 16);
        }

        return size;
    }

The data_from_string function is a used by Bluez to encode a character string and sent it to a connected device. It does produce an encoded (uinit_8) value array as follows:

0000000A0000EC0D0000000004FA304FE9E91BED21E3C5898796056CE4E590E12BC74D0219A185D2E0B9B49A7393F023415F3E1FFD22D5B0A134E03F84D5C5DF7C5326C51971CFB783A26F16360000000E00411C41FC2ECB6F6F482050C005B30F75E134FD8AEA1E45F687A9E995CCFFB14DDD8EA41462E41CAEBA2AA21CA8F70C67FF4AA6620E64BABA23CCA0088F2922560D00000000

I was looking for a means to restore the encoded (uinit_8) value array back to its original text representation.

Does anyone have a notion how to perform this task?

Ed Johns
  • 211
  • 3
  • 11
  • Yes, any C or C++ programmer should have a notion how to perform that task. – Ulrich Eckhardt May 09 '15 at 17:53
  • Thanks. I just thought someone would have some sample code. – Ed Johns May 09 '15 at 18:20
  • As I already stated in https://stackoverflow.com/questions/30133364/covert-compressed-hex-string-base-64-encoded: you can only encode the "04FA304FE9E91BED21E3C..." part with `data_from_string`. The rest of the string will be corrupted and cannot be recovered. (you will recognize this part in your binary representation) – j.holetzeck May 09 '15 at 19:53

0 Answers0