Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Experts,

I made one small desktop application in C#.net. My requirement is i want to encrypt a text file using RSA Algorithm. I already done this encyption using CAPICOMM.dll, but now I want to do it using RSA Algorithm in which I will use Public key to encrypt the file and Private key to decrypt the encrypted file.

Below is my code that I implemented but it gives me an error!!:confused:

C#
UnicodeEncoding ByteConverter = new UnicodeEncoding();
byte[] dataToEncrypt = ByteConverter.GetBytes("Hello there");
byte[] encryptedData;
byte[] decryptedData;
//Create a new instance of RSACryptoServiceProvider to generate
//public and private key data.
//CspParameters param = new CspParameters(
using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
{
    //Pass the data to ENCRYPT, the public key information
    RSA.FromXmlString(SelectedCertificate.PublicKey.Key.ToXmlString(false));
    encryptedData = RSA.Encrypt(dataToEncrypt, false);
    //Pass the data to DECRYPT, the private key information
    RSA.FromXmlString(SelectedCertificate.PrivateKey.ToXmlString(false));
    decryptedData = RSA.Decrypt(encryptedData, false);
    //Display the decrypted plaintext
}


Need your suggestion. Thanks in advance...

[edit]Tags, minor spelling - OriginalGriff[/edit]
Posted
Updated 13-Jul-10 1:12am
v2
Comments
OriginalGriff 13-Jul-10 7:13am    
What error do you get? Where do you get it?
Is it a run time error - if so, what is the exception?

1 solution

Hey..
I think you can find ,understand and use the method that is Here
Hope this helps... ;P
 
Share this answer
 
v2

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