Below are the partial codes of my udp server and client.
I am not sure is it the issues with UDP that my output is wierd but it is always on the 16th word that something is wrong?
define MAX_ENCRYPT_MSG_SIZE 16
On the server side :
char tempStr[MAX_ENCRYPT_MSG_SIZE];
/***** GET INPUT CODE HERE *****/
int tempLen = strlen(tempStr)+1;
//encrypt msg
ct = aes_encrypt(ci->getEVPCipherEN(),(unsigned char*) tempStr, &tempLen);
//send msg
rc = sendto(*(ci->getSd()), ct, tempLen, 0,(struct sockaddr *) ci->getCliAddr(),*(ci->getCliLen()));
On the Client Side :
int iLen = MAX_ENCRYPT_MSG_SIZE;
char msg[MAX_ENCRYPT_MSG_SIZE];
n = recvfrom(*(ci->getSd()), msg, iLen, 0,(struct sockaddr *) ci->getCliAddr(),ci->getCliLen());
char pt[16];
char *plaintext = (char *)aes_decrypt(ci->getEVPCipherDE(),(unsigned char*) msg, &iLen);
//convert back to only 16 bytes
strcpy(pt,plaintext);
if(plaintext == NULL)
{
std::cout << "Error" << std::endl;
}
else
{
std::cout << pt << std::flush;
}
Output :

Thanks in advance! 🙂
c strings need space for a null byte in the end? is that it?