how to store HEX in a uint8_t ?

with this part of my code i print the 64 bit ciphertext in HEX in 4 rows of 16
how can i store the ciphertext in a uint8_t[64] for the decryption
i cant understand the sprintf
any help?
can anyone explain "for dummies" what is happening in phex function

static void phex(uint8_t* str)
{
 char msg[70];
   unsigned char i;
   for(i = 0; i < 16; ++i){
           sprintf(msg, "%2x", str[i]);
        Serial.print(msg);
   }
}
// print the resulting cipher as 4 x 16 byte strings
   Serial.print("ciphertext:\n");          

   for(i = 0; i < 4; ++i)
   {
       AES128_ECB_encrypt(plain_text + (i*16), key, buf+(i*16));
               phex(buf + (i*16));
   }

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

phex prints 16 bytes :wink: It takes a pointer to an array (of type uint8_t). The sprintf creates a string from the variable(s) that you pass as the third, fourth etc argument; in your case str[i] which is the i-th element of the buffer that you pasded to phex.. How it creates the string depends on what is specified in the second argument ( in this case %2x). The result will be placed in the buffer specified by the first argument.

%2x indicates that the value of the variable is printed as a hexadecimal value (%x) with at least 2 positions (the 2 in %2x); %02x might have beeb neater as it will print a leading zero instead of a leading space when the value to print is less than 16 (0x10).

msg is actually far too big as it only needs to hold 2 characters and a null terminating character.

//edit
As far as I can see, your cypher text is already in a uint8_t (assumption) array. You can simply pass buf to the decryption routine. If you have problems, please post the complete code.

Thanks!!!! That actually helped a lot !!