January 18
2009

RSA Cryptography in C# Tutorial, Part 2

C# Tutorial Windows

Next is the Public and private key generator. In my RSA Crypto program, I used threading so this wouldn’t interrupt the GUI, but you don’t have to.

The next step is to make a new RSACryptoServiceProvider( included in the Cryptography library), which will create the key. Mine is called RSAcsp. The parameter this takes is the bit-strength, which can be a set number, or user chosen. You will want something between 1024 and 2048 for this one.

Next, save the public and private keys into strings, with (RSA CSP name).ToXmlString. To make the private key use RSAcsp.ToXmlString(true), and for the public key, RSAcsp.ToXmlString(false). Then save these to 2 files, the public key ending in .pke, and the private key ending in .kez. These seem to be the standard extensions, but you can use whatever you like.

RSA-Keys

Next time i will show you how to turn the plaintext into byte data for 2048 bitstrength keys. I will tell you at a later time how to convert it for any bitstrength.

3 Comments on “RSA Cryptography in C# Tutorial, Part 2”

  1. nice work i need da link plz

  2. Digitalsquid

    the main article + source code is here, http://digitalsquid.co.uk/2009/01/rsa-crypto/

Leave a Reply