Key Issue of sharing

OverView

 

Key issue plays very important role in cryptography. Whatever a strong crypto algorithm or key uses but if your key sharing way does not secure means there is no security of data. Key may get a hacker and can decrpt your cipher then where will be your security.

There are may ways to send Symmetric key. One of ways and more secure way is xmlfile way.Mostly people like to use this way.There are two method uses ToXmlString and FromXmlString. If you pass true in ToXmlString as parameter, it returns you public & private key and if pass false, it reutrns only public key.Using FromXmlString method, get Public & private key combination (difficult to distingush between public and private key) and decrypt encrypted symmetric key and using that symmetric key, you can decrypt your actual data.

 

Example

 

In this example, I am using RSA Asymmetric algorithm for key encryption and xmlfile for key sharing one place to another. Using RSA object of RSACryptoServiceProvider, getting ToXmlString method and passing true as parameter and getting returning value (public and private keys combination) into a string and saving into xml exstension file which will share to other user who will decrypt key and data too.

 

#region write RSA (Public Private) key in xml files

RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();

StreamWriter writer = new StreamWriter("PublicPrivateKey.xml");

string publicprivatexml = RSA.ToXmlString(true);

writer.Write(publicprivatexml);

writer.Close();

#endregion

 

Other end, getting xml file using ftp and read that xml file and passes all data into a string which passes as parameter to RSA method, FromXmlString. Now RSA object has capabilited to decrypt encrypted symmetric key which will decrypt large size of data.

 

#region key decryption

RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();

StreamReader reader = new StreamReader("PublicPrivateKey.xml");

string publicprivatekeyxml = reader.ReadToEnd();

RSA.FromXmlString(publicprivatekeyxml);

reader.Close();

#endregion
 

Up Next
    Ebook Download
    View all
    Learn
    View all