Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

In a client/server application, the server is sending an encrypted value to the client:

C++
const char * Enc_Message2 = AES_Encrypt(Message2, Shared_Session_Key_S, I_V);
	cout<<"\n\nENCRYPTED MESSAGE2 {S,nb,ns}:";
	cout<<"\n============================="<<"\r\n"<<Enc_Message2;
	//cout<<"\n\nSIZE OF ENCRYPTED MESSAGE2: "<<sizeof(Enc_Message2);
	//cout<<"\n\nSIZE OF ENCRYPTED MESSAGE2 {S,nb,ns}: "<<sizeof(Enc_Message2);

	s5 =clientSock->SendString(Enc_Message2);
	 if (s5 != true) {
		std::cout << clientSock->lastErrorText() << "\r\n";
		return;	}


Although the client receives the value, it receives it with a missing first character.

C++
const char * Recieved_Enc_Msg2 = 0;
	 Recieved_Enc_Msg2 = socket.receiveString();
		if (Recieved_Enc_Msg2 == 0 ) {
		std::cout << socket.lastErrorText();
		return;
	}
	std::cout<<"\n\nRECIEVED MESSAGE2: "<<"\r\n"<<Recieved_Enc_Msg2;



Can someone please help me!

What I have tried:

1- I used the std::cout, but it didn't work.
Posted
Updated 15-Dec-16 11:28am

1 solution

Hi again,

I've just fixed it, by adding the following code at the server-side, right before sending the encrypted result.


C++
int e = strlen(Enc_Message2);
	char * enc_msg2 = new char[e+1];
	strcpy(enc_msg2, Enc_Message2);

5 =clientSock->SendString(enc_msg2);
	 if (s5 != true) {
		std::cout << clientSock->lastErrorText() << "\r\n";
		return;	}


best regards.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900