using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography;
using RSAKeyGenerator;
namespace RSAKeyGenerator
{
public partial class FrmRSAKeyGen : Form
{
public FrmRSAKeyGen()
{
InitializeComponent();
}
private void CmdExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void CmdGenerate_Click(object sender, EventArgs e)
{
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(1024);
RSAParameters RSAKeyInfo = rsa.ExportParameters(true);
string str="";
str += GetKeyText("parammodulus", RSAKeyInfo.Modulus) + "\r\n";
str += GetKeyText("exponent", RSAKeyInfo.Exponent) + "\r\n";
str += GetKeyText("paramdp", RSAKeyInfo.DP) + "\r\n";
str += GetKeyText("paramdq", RSAKeyInfo.DQ) + "\r\n";
str += GetKeyText("paramp", RSAKeyInfo.P) + "\r\n";
str += GetKeyText("paramq", RSAKeyInfo.Q) + "\r\n";
str += GetKeyText("inverseq", RSAKeyInfo.InverseQ) + "\r\n";
str += GetKeyText("paramd", RSAKeyInfo.D) + "\r\n";
TxtCode.Text = str;
}
private string GetKeyText(string name, byte[] param)
{
string str="";
str = "byte " + name + "[] = " + GetByteStr(param) + ";";
return str;
}
private string GetByteStr(byte[] param)
{
string str="{";
for (int i = 0; i <= param.Length - 1; i++)
{
if (i== param.Length - 1)
str += param[i].ToString();
else
str += param[i].ToString() + ",";
}
str += "}";
return str;
}
private void FrmRSAKeyGen_Load(object sender, EventArgs e)
{
}
}
}