How can I generate a new key pair?

Jan 24, 2011 at 2:19 PM

I see the public/private keys stored as embedded resources in the projects. That brings up two questions:

  1. How do I generate a new pair for my specific implementation?
  2. Do I need to?

Thanks!
-Mike

Jan 26, 2011 at 8:59 PM

Hi Mike,

You need to create your own key par and replace it in the source code.

The following code shows how to create the private and public key. Remember that the private key must be kept secret. The public key may be distributed in your application. If by mistake you distribute the private key, everybody will be able to generate valid product keys.

usingSystem;
usingSystem.IO;
using System.Security.Cryptography;

namespaceConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
            using (StreamWriter writer = new StreamWriter("PrivateKey.xml"))
            {

                writer.WriteLine(rsa.ToXmlString(true));

            }
            using (StreamWriter writer = new StreamWriter("PublicKey.xml"))
            {

                writer.WriteLine(rsa.ToXmlString(false));           

            }
        }
    }
} 

Hope this helps,

Alvaro