private void GenerujKluczeButton_Click(object sender, RoutedEventArgs e) { try { WyznaczPiQ(); WyznaczN(); WyznaczPHI(); WyznaczE(); WyznaczD(); public_keyA = new RSA_key(Na, Ea); private_keyA = new RSA_key(Na, Da); public_keyB = new RSA_key(Nb, Eb); private_keyB = new RSA_key(Nb, Db); KluczPublicznyLabel.Content = "Wygenerowany"; KluczPrywatnyLabel.Content = "Wygenerowany"; KluczPublicznyLabel.Foreground = Brushes.Green; KluczPrywatnyLabel.Foreground = Brushes.Green; PodglądZmiennych.IsEnabled = true; ZapiszKluczPublicznyButton.IsEnabled = true; ZapiszKluczPrywatnyButton.IsEnabled = true; KluczPublicznyLabelB.Content = "Wygenerowany"; KluczPrywatnyLabelB.Content = "Wygenerowany"; KluczPublicznyLabelB.Foreground = Brushes.Green; KluczPrywatnyLabelB.Foreground = Brushes.Green; ZapiszKluczPublicznyButtonB.IsEnabled = true; ZapiszKluczPrywatnyButtonB.IsEnabled = true; } catch (Exception ex) { MessageBox.Show("Wystapil nieoczekiwany błąd \n\n\n" + ex); } }
private void WczytajKluczPrywatny_Click(object sender, RoutedEventArgs e) { try { OpenFileDialog openFileDialog1 = new OpenFileDialog { Title = "Wybierz plik z kluczem publicznym", Filter = "Public Key (*.publickey)|*.publickey", FilterIndex = 1, RestoreDirectory = true }; if (openFileDialog1.ShowDialog() == true) { using (StreamReader sr = new StreamReader(openFileDialog1.FileName)) { BigInteger n1 = BigInteger.Parse(sr.ReadLine()); BigInteger e1 = BigInteger.Parse(sr.ReadLine()); public_key_wczytanyA = new RSA_key(n1, e1); } } LabelKluczPrywatny.Foreground = Brushes.Green; LabelKluczPrywatny.Content = "Wczytany"; DeszyfrujTekstButton.IsEnabled = true; } catch (Exception ex) { MessageBox.Show("Nie udało się wczytać klucza"); } }
private BigInteger Decrypt(RSA_key private_key, BigInteger c) { return(BigInteger.ModPow(c, private_key.x, private_key.n)); }
private BigInteger Encrypt(RSA_key public_key, BigInteger m) { return(BigInteger.ModPow(m, public_key.x, public_key.n)); }