rsa encrypt/decrypt

From: Taryon (taryon_at_terra.com.br)
Date: 09/11/03


Date: Thu, 11 Sep 2003 15:02:18 -0300


hi all!
i am using the rsa to encrypt one password on the server and decrypt it on
the client. The server code is:

ASCIIEncoding UEConv = new ASCIIEncoding();
fs = new FileStream("pb"+conta+".txt",FileMode.Open);
StreamReader sr = new StreamReader(fs);
String rsaPubKey = sr.ReadToEnd();
rsa.FromXmlString(rsaPubKey);
fs.Close();
byte[] plaintext = UEConv.GetBytes(keyinuse);
byte[] ciphertext = rsa.Encrypt(plaintext,false);
string chave=new String(UEConv.GetChars(ciphertext));

and in the client i have this:

ASCIIEncoding BC = new ASCIIEncoding();
byte[] ciphertext = BC.GetBytes(serverrespkey);
fs = new FileStream(privfile,FileMode.Open);
StreamReader sr1 = new StreamReader(fs);
String rsaPrivKey = sr1.ReadToEnd();
rsa.FromXmlString(rsaPrivKey);
fs.Close();
byte[] rgbPlainText = rsa.Decrypt(ciphertext,false);
string keyinuse=new String(BC.GetChars(rgbPlainText));

exactly in the decrypt line i got a BAD DATA. I look through the watch that
the result of the encryption is equal to the ciphertext in the decrypt.
any idea?
PS. the Client receive the serverrespkey through a socket connection and
this connection is working fine to no crypted texts.



Relevant Pages

  • Re: Confused by CryptoAPI
    ... ANYBODY would be able to decrypt it and recover ... random salt (encrypted by the session key) and get that signed. ... that case if the signature of the salt is OK you know that the server ... then the server sends the signature back to the client. ...
    (microsoft.public.platformsdk.security)
  • Re: Windows->Linux. Graphical terminal emulator.
    ... client generete and send to server a random number using RSA ... > have the servers public key until it contacts the server, ... Private key can only encrypt information but not decrypt it. ...
    (alt.linux)
  • Re: Windows->Linux. Graphical terminal emulator.
    ... client generete and send to server a random number using RSA ... > have the servers public key until it contacts the server, ... Private key can only encrypt information but not decrypt it. ...
    (alt.os.linux)
  • RE: Securing OWA w/SSL on IIS5.0
    ... Client inspects provided credentials for validitity. ... A symetric key is negotiated and exchanged using the public/private keypair of the server certificate. ... The whole process relies on the concept of public key cryptography which in short means that for every encryption key there is a seperate corresponding decryption key. ... > couldn't they just replay the information to decrypt the data arriving at ...
    (Focus-Microsoft)
  • Re: Features for a monitoring tool
    ... Then possibly a user interface for the server ... > originated by the client, without the server polling for the info. ... What I thought I would do was a monitoring client that asked the ... > so the server will need means to decrypt the password. ...
    (comp.os.linux.security)