So I am looking to append the length of a cipher text onto the end of the char array that I am storing the cipher in. I am not a native to C and below is a test snippet of what I have devised that I *think* works.

```
...
int cipherTextLength = 0;
unsigned char *cipherText = NULL;
...
EVP_EncryptFinal_ex(&encryptCtx, cipherText + cipherTextLength, &finalBlockLength);
cipherTextLength += finalBlockLength;
EVP_CIPHER_CTX_cleanup(&encryptCtx);

// Append the length of the cipher text onto the end of the cipher text
// Note, the length stored will never be anywhere near 4294967295 
char cipherLengthChar[1];
sprintf(cipherLengthChar, "%d", cipherTextLength);
strcat(cipherText, cipherLengthChar);
printf("ENC - cipherTextLength: %d\n", cipherTextLength);
...

```

The problem is I don't think using `strcat` when dealing with binary data is going to be trouble free. Could anyone suggest a better way to do this?

Thanks!

**EDIT**

Ok, so I'll add a little context as to why I was looking to append the length. In my `encrypt` function, the function `EVP_EncryptUpdate` requires the length of the `plainText` being encrypted. As this is much more easy to obtain, this part isn't a problem. However, similarly, using `EVP_DecryptFinal_ex` in my `decrypt` function requires the length of the `ciperText` being decrypted, so I need to store it somewhere.

In the application where I am implementing this, all I am doing is changing some poor hashing to proper encryption. To add further hassle, the way the application is I first need to decrypt information read in from XML, do something with it, then encrypt it and rewrite it to XML again, so I need to have this cipher length stored in the cipher somehow. I also don't have scope to redesign this.