My project is Email project. In my project i want to Encrypt the sender message with his public key and decrypt the at Recepient side message using Senders private Key.The problem means When i entered some characters in textbox its encryptd.If i entered Some big files or more then two lines the error has been generated.The generated error is Key value is not valid.Im using 1024 bit key length.I have applied the brake point and checked my error its shows the key value is 472.But im using 1024 bit key length.So i could not get it Where i made the blunder.Here is the code

string plaintext = txttext.Text;

int keysize = 1024;

// By default it will create RSA keys

RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(keysize);

// Write to this file all rsa data

FileStream fs = new FileStream("rsa.xml", FileMode.OpenOrCreate, FileAccess.Write);

// This will produce all RSA data, including private key

byte[] rsadata = Encoding.ASCII.GetBytes(/*"<BitStrength>" + keysize.ToString()+*/ rsa.ToXmlString(true));

fs.Write(rsadata, 0, (int)rsadata.Length);

fs.Close();

//Initialize the the public key information.

const string publickey = ("\\keygeneration\\rsa.xml");

const string exponent = @"AQAB";

RSAParameters rsaKeyInfo = new RSAParameters();

//Set RSAKeyInfo to the public key values.

rsaKeyInfo.Modulus = Encoding.ASCII.GetBytes(publickey);

rsaKeyInfo.Exponent = Encoding.ASCII.GetBytes(exponent);

//Import key parameters into RSA.

rsa.ImportParameters(rsaKeyInfo);

try

{

byte[] ciphertext = rsa.Encrypt(Encoding.ASCII.GetBytes(plaintext), false);

encrypt = Encoding.ASCII.GetString(ciphertext);

}

catch (Exception ex)

{

Response.Write(ex.Message);

}

}

Please some one help me how to avoid this problem.........................

Regards

M.Rahul