Click here to Skip to main content
15,885,985 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

https://msdn.microsoft.com/en-us/library/bb397867(v=vs.110).aspx[^]

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.
C#
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";
            else
                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 
           
            objr.GetPrivateKey();
           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);.


Please..
Posted
Updated 22-Sep-15 18:48pm
v4

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: https://en.wikipedia.org/wiki/Public-key_cryptography[^].

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.

—SA
 
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