private void BtnGetRSAElements_Click(object sender, EventArgs e) { //65537 var primes = RSACrypto.RSAHelper.GeneratePrimes(10000); var result = RSACrypto.RSAHelper.GetTwoPrimes(primes); string Prime1 = primes[(int)result[0]].ToString(); string Prime2 = primes[(int)result[1]].ToString(); var N = primes[(int)result[0]] * primes[(int)result[1]]; p = Convert.ToUInt64(primes[(int)result[0]]); q = Convert.ToUInt64(primes[(int)result[1]]); textBox2.Text = Prime1; textBox3.Text = Prime2; textBox8.Text = N.ToString(); // //call the function for calculating e here var phi = RSAlgorithm.Phi(p, q); EDForm.e = RSAlgorithm.Find_E(phi); bool flag = false; for (ulong j = 1; !flag; j++) { if ((EDForm.e * j) % phi == 1) { d = j; flag = true; break; } } //Set Public and Private Key textBox4.Text = EDForm.e.ToString(); textBox9.Text = d.ToString(); if (MakerCheckerMessageMemoEdit.Text.Trim() == "") { MakerCheckerMessageMemoEdit.Text = "P=" + Prime1 + ", Q=" + Prime2 + ", N=" + N + System.Environment.NewLine + "Public Key=[" + EDForm.e.ToString() + "," + N + "]" + System.Environment.NewLine + "Private Key=[" + d.ToString() + ", " + N + "]"; } else { MakerCheckerMessageMemoEdit.Text = MakerCheckerMessageMemoEdit.Text + System.Environment.NewLine + "_______________________________________________" + System.Environment.NewLine + "P=" + Prime1 + ", Q=" + Prime2 + ", N=" + N + System.Environment.NewLine + "Public Key=[" + EDForm.e.ToString() + "," + N + "]" + System.Environment.NewLine + "Private Key=[" + d.ToString() + ", " + N + "]"; } //button3.Text = "Reset Details"; Application.DoEvents(); }
public static object[] PopulateKeys(ulong e, ulong d, ulong p, ulong q, params TextBox[] textBoxes) { var primes = GeneratePrimes(10000); var result = GetTwoPrimes(primes); string Prime1 = primes[(int)result[0]].ToString(); string Prime2 = primes[(int)result[1]].ToString(); var N = RSAlgorithm .N((ulong)primes[result[0]], (ulong)primes[result[1]]); p = Convert.ToUInt64(primes[result[0]]); q = Convert.ToUInt64(primes[result[1]]); textBoxes[0].Text = Prime1; textBoxes[1].Text = Prime2; textBoxes[2].Text = N.ToString(); var phi = RSAlgorithm.Phi(p, q); e = RSAlgorithm.Find_E(phi); bool flag = false; for (ulong j = 1; !flag; j++) { if ((e * j) % phi == 1) { d = j; flag = true; } } textBoxes[3].Text = e.ToString(); textBoxes[4].Text = d.ToString();; var returnValues = new object[] { p, q, N, e, d }; return(returnValues); }