Click here to Skip to main content
15,936,821 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am developing an encryption decryption software.I used RSA encryption to encypt my symmetric key.

I followed the code provided in the link[^]

My encryption and decryption done successfully in same machine.But when I tried to decrypt from other computer,an error :bad data is occuring.(It can be decrypted from same machine.)

How to publish my public key to other systems inorder to decrypt form different system.

Please help me ,give me an idea to decrypt from different machines.
public void GetPrivateKey()
            string c;
            cspp.KeyContainerName = keyName;

            rsa = new RSACryptoServiceProvider(cspp);
            rsa.PersistKeyInCsp = true;
            if (rsa.PublicOnly == true)
                c= "Key: " + cspp.KeyContainerName + " - Public Only";
                c = "Key: " + cspp.KeyContainerName + " - Full Key Pair";
 public string decryptkey(string at)
            byte[] KeyEncrypted;
            KeyEncrypted = File.ReadAllBytes(at);
            //System.IO.File.ReadAllBytes(at);//for good 
           byte[] KeyDecrypted = objr.rsa.Decrypt(KeyEncrypted, false);
            string skey = GetString(KeyDecrypted);
            return skey;

Bad data Error happens in this line,
byte[] KeyDecrypted = objr.rsa.Decrypt(KeyEncrypted, false);.

Updated 22-Sep-15 18:48pm

1 solution

The question makes no sense. The private key is always private, it does not need to be passed through the network, and never ever should be. You are missing the whole idea of public-key encryption. You have to learn it, because it's very important. So, please see:[^].

In brief: you encrypt with one key, decrypt with another one. If the purpose is encryption (not digital signature), the key sent over network is only the key to encrypt, and the key to decrypt is kept private. If you don't see what to do with it, learn from what Alice and Bob do.

Share this answer

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