Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using RSA to encrypted text and then send the encryptedtext to server ,My problem is the server unable to decrypted text because the server can not read encryptedtext correct , my code in client is :
C#
byte[] plaintext;
            byte[] encryptedtext=new byte[128];
            plaintext = ByteConverter.GetBytes("hello");
            encryptedtext = Encryption(plaintext, RSAA.ExportParameters(false), false);
            textBox10.Text = ByteConverter.GetString(encryptedtext);

          byte[] bytesToSend = ASCIIEncoding.ASCII.GetBytes(textBox10.Text);
          networkStream.Write(bytesToSend, 0, bytesToSend.Length);

my code in server :

C#
byte[] buffer = new byte[handlerSocket.ReceiveBufferSize];
 dataReceived = Encoding.ASCII.GetString(buffer, 0, buffer.Length);
            byte[] encryptedtext=new byte[128] ;
         //   dataReceived = ByteConverter.GetBytes(dataReceived);
            encryptedtext = ByteConverter.GetBytes(dataReceived);
            byte[] decryptedtex = Decryption(encryptedtext, RSA.ExportParameters(true), false);
               if(decryptedtex!=null)
            textBox4.Text = ByteConverter.GetString(decryptedtex);

output :

in client the encrypted text : 卅凉䂧즠淦燺◓㎜ზᄋ큺�㬧ᶥ숿둴ꖉ␽넵Տ懾쵌摘䙑원퀮歒�숈鬖姈㫑餓貜Dž手葏㻐㺿⣨ꇑ橿朁繱�䘧殍㲙㦱䟽躮Ồᒛ鈉嫡짟

but when the encrypted text recive to server is : ????????????????????????????????????????????????????????? and the server can not Decryption the text

so How I can solve this problem ?

What I have tried:

my code in my question can any body help ? thanks in advance
Posted
Comments
Richard MacCutchan 30-Nov-16 14:16pm    
The display of the encrypted text is not relevant. The issue is whether the server has the correct information (key etc.) to decrypt the data that it receives.
Member 12702368 30-Nov-16 14:21pm    
yes server has the correct information (key etc.) to decrypt the data but it can not decrpt the massage
#realJSOP 1-Dec-16 5:44am    
Can your client app decrypt the encrypted text?
Member 12702368 3-Dec-16 4:30am    
yes , client app decrypt the encrypted text

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