RSA ;)

From: Ronny Engen (ronny@nospaminlecom.com)
Date: 09/27/02


From: "Ronny Engen" <ronny@nospaminlecom.com>
Date: Fri, 27 Sep 2002 17:13:45 +0100

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);