How do I store a 16 byte binary value that can be represented as a 32 hexadecimal characters in an unsigned char* variable in C

#define SECRET { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b , 0x0b , 0x0b , 0x0b , 0x0b , 0x0b , 0x0b , 0x0b , 0x0b}
unsigned char* key = SECRET;

is not correct. You can use:

#define SECRET { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b , 0x0b , 0x0b , 0x0b , 0x0b , 0x0b , 0x0b , 0x0b , 0x0b}
unsigned char key[] = SECRET;  // Change key to an array.

If you must you use a pointer, you can create two variables.

#define SECRET { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b , 0x0b , 0x0b , 0x0b , 0x0b , 0x0b , 0x0b , 0x0b , 0x0b}
unsigned char key_array[] = SECRET;
unsigned char* key =  key_array;

Leave a Comment