pointeman
asked on
TextBox base64 Encoding and Padding?
Go figure, for what ever reason, loading the received data into a textbox converts the data into base64 and either corrects or preserve the padding.
Q. How can I avoid using a TextBox and give the Decrypt the encoding and padding it requires?
public void DataRcvd(IAsyncResult aResult)
{
string dataEncrypted = Encoding.ASCII.GetString(s kt.byteBuf fer, 0, skt.byteBuffer.Length);
textBox_ReceivedMsg.Text = dataEncrypted;
string dataDECRYTPED = myCrypto.Decrypt(txtReceiv edMsg.Text , "password123");
textBox_Decrypted.Text = dataDECRYTPED;
}
Q. How can I avoid using a TextBox and give the Decrypt the encoding and padding it requires?
public void DataRcvd(IAsyncResult aResult)
{
string dataEncrypted = Encoding.ASCII.GetString(s
textBox_ReceivedMsg.Text = dataEncrypted;
string dataDECRYTPED = myCrypto.Decrypt(txtReceiv
textBox_Decrypted.Text = dataDECRYTPED;
}
ASKER
Yes, I have since change the code to UTF8 encoding, but still same problem.
I'm using the following TCP Sockets Server/Client example: http://www.codeguru.com/Cs harp/Cshar p/cs_netwo rk/sockets /article.p hp/c8781/
The server is the problem because it has a fixed buffer of [1024], whereas the cypherTextBytes needs to vary to match the client byte count.
http://www.obviex.com/samp les/Encryp tion.aspx
I accidentially discovered dumping the encrypted string into a TextBox1.Text will come-out converted to base64 and the correct byte.length of 400(per test string) to satisfy the cypherTextBytes like so:
public void OnDataReceived(IAsyncResul t asyn)
{
string message = Encoding.UTF8.GetString(so cketData.d ataBuffer, 0, socketData.dataBuffer.Leng th);
TextBox1.Text = message;
}
private void ButtonDecrypt_Click(object sender, EventArgs e)
{
string data = myCrypto.Decrypt(TextBox1. Text, "password123");
TextBox2.Text = data; });
}
Obviously I want to eliminate the TextBox1...
I'm using the following TCP Sockets Server/Client example: http://www.codeguru.com/Cs
The server is the problem because it has a fixed buffer of [1024], whereas the cypherTextBytes needs to vary to match the client byte count.
http://www.obviex.com/samp
I accidentially discovered dumping the encrypted string into a TextBox1.Text will come-out converted to base64 and the correct byte.length of 400(per test string) to satisfy the cypherTextBytes like so:
public void OnDataReceived(IAsyncResul
{
string message = Encoding.UTF8.GetString(so
TextBox1.Text = message;
}
private void ButtonDecrypt_Click(object
{
string data = myCrypto.Decrypt(TextBox1.
TextBox2.Text = data; });
}
Obviously I want to eliminate the TextBox1...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I see you've worked with sockets before, great job and good eye. I'm new to TCP sockets, always used TcpClient and Listen, so Sockets is a real adventure. More work, but well worth the extended benefits...
Concerning the TextBox and base64 encoding: I kept receiving base64 and padding errors and discoved by accident a Textbox solved all my problems. It didn't make any sense to me either...
Thanks for all your help, you'll probably see my here again concerning TCP Sockets....
Concerning the TextBox and base64 encoding: I kept receiving base64 and padding errors and discoved by accident a Textbox solved all my problems. It didn't make any sense to me either...
Thanks for all your help, you'll probably see my here again concerning TCP Sockets....
ASKER
Thanks again...
Glad you've got it working.
What type is the myCrypto object? It's obviously a wrapper around a crypto transform. But if you're able to pass a string to myCrypto.Decrypt, is there some reason why you can't pass the dataEncrypted string to the method?
Open in new window