Link to home
Start Free TrialLog in
Avatar of pointeman
pointemanFlag for United States of America

asked on

Sockets ASCII & Base64 Encryption Problems?

I'm building a typical TCP Socket Server / Client in the usual way. Now I have a problem after encrypting the data. Both Client and Server have identical myCrypto classes and password123. I don't receive errors performing the Encryption on the Client, just during Decryption on the Server...

[Client]
publice void SendData(string message)
{
     Object oData = myCrypto.Encrypt(message, "password123");
     byte[] byteData = System.Text.Encoding.ASCII.GetBytes(oData.ToString());
}

[Server]
public  void DataRcvd(IAsyncResult aResult)
{
     string dataEncrypted = Encoding.ASCII.GetString(skt.byteBuffer, 0, skt.byteBuffer.Length);                                
     string dataDecrypted = myCrypto.Decrypt(dataEncrypted, "password123");
}
Avatar of williamcampbell
williamcampbell
Flag of United States of America image

does (Server) string dataEncrypted   Equal (Client)  oData.ToString()  ?
Avatar of pointeman

ASKER

I'm check that out now...
Go figure, for what ever reason, loading the received data into a textbox somehow fixes the problem, although I don't want to use a textbox because the Win-App is just a testing project to eventually build a Win-Service later....
public  void DataRcvd(IAsyncResult aResult)
{
     string dataEncrypted = Encoding.ASCII.GetString(skt.byteBuffer, 0, skt.byteBuffer.Length);                                
     
     textBox_ReceivedMsg.Text = dataEncrypted;

     string dataDECRYTPED = myCrypto.Decrypt(txtReceivedMsg.Text, "password123");

     textBox_Decrypted.Text = dataDECRYTPED;
}
 
Maybe the line below will do it
string dataEncrypted = Convert.ToString (Encoding.ASCII.GetString(skt.byteBuffer, 0, skt.byteBuffer.Length));  
 
or
 
string dataEncrypted = Encoding.ASCII.GetString(skt.byteBuffer, 0, skt.byteBuffer.Length).ToString ();  

Open in new window

No, both code suggestions failed because I now need to convert to base64, which I did, then I receive a padding error....
I guess I need to investigate how a TextBox converts input data.
ASKER CERTIFIED SOLUTION
Avatar of pointeman
pointeman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial