Re: RSA ;)

From: Sitaraman (l.sitaraman@verizon.net)
Date: 09/27/02


From: "Sitaraman" <l.sitaraman@verizon.net>
Date: Fri, 27 Sep 2002 12:48:32 -0400

Hi Ronny
I am not sure what do you mean by "Custom Keys". RSA Algorihm requires paramets like Modulus, Exponent,etc.
There are two ways you can feed your keys.
a) in .NET you can use

TO Export the Public Key ( instead of using ExportParameters)
   RSACryptoServiceProvider objRSAProvider = new RSACryptoServiceProvider();
   string strPubKey = objRSAProvider.ToXmlString(true);

To Import the Public key.
 RSACryptoServiceProvider objRSAProviderPublic = new RSACryptoServiceProvider();
   objRSAProviderPublic.FromXmlString(strPubKey);

b) If you can generate the Keys from a different language like Java , you need to figure out to get the parameters like Modulus , Exponent and
the you should set the rsaParametes and then Import it.

Yes the Keys used are Purely Random Keys and you may want to look at www.rsa.com or IETF references to see how the random keys are generated
and the concept behind the large Prime Numbers.

If you are going to set your own Prime Numers , then i am afraid the keys may not be "Strong" keys.

I hope this helps.

Sitaraman

"Ronny Engen" <ronny@nospaminlecom.com> wrote in message news:e4achCkZCHA.2516@tkmsftngp10...
  Hi Newsgroup, I have been playing around with RSA/reading some articles about how to use it. Basically I have been able to take some contents form a textbox encrypt it and then decrypt it.

  However, I have not been able to work my way around the mechanisms 100%. I have not yet been able to understand how you can actually use custom keys. I.e. I want to create a set of custom keys (how do I do this) and I want to be able to feed the RSA implementation with these keys, currently it appears to me as if it is "purely random keys" that are being used.

  It would be grateful if anybody knows about any books or articles which is good on this issues, perhaps you even have some code to show me how to do this.

  Thank you in advance
         -Ronny Engen

  //Example (working) code:

  RSAParameters rsaParam;

  CspParameters CSPParam = new CspParameters();

  CSPParam.Flags = CspProviderFlags.UseMachineKeyStore;

  RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(CSPParam);

  byte[] byteInput = (new System.Text.UnicodeEncoding()).GetBytes(textBox1.Text);

  byte[] byteEncrypted = rsa.Encrypt(byteInput, false);

  rsaParam = rsa.ExportParameters(true);

  textBox2.Text = (new System.Text.UnicodeEncoding()).GetString(byteEncrypted);

  rsa.ImportParameters(rsaParam);

  byte[] byteEncryptedString = (new System.Text.UnicodeEncoding()).GetBytes(textBox2.Text);

  byte[] byteDecryptedString = rsa.Decrypt(byteEncryptedString, false);

  textBox3.Text = (new System.Text.UnicodeEncoding()).GetString(byteDecryptedString);