<commit_before>﻿using System;
using PgpSharp.GnuPG;
using System.Windows.Forms;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.Security;
using System.IO;
using Org.BouncyCastle.Math;
using Org.BouncyCastle.Bcpg.OpenPgp;
using Org.BouncyCastle.Bcpg;

namespace Encrypted_messager
{
    public partial class CreateKeys : Form
    {
        public CreateKeys()
        {
            InitializeComponent();
            this.ControlBox = false;
            MessageBox.Show("It seems that this is the first run. Please create a pair of keys. Fill the form to continue.");
        }

        private void CreateKeys_Load(object sender, EventArgs e)
        {
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (passwordTextBox.Text == repeatPassowrdTextBox.Text)
            {
                MessageBox.Show("The program will now generate the keys. This may take some time. Please wait patiently.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Keys.GenerateKeys(textBox1.Text, passwordTextBox.Text);
                this.Close();
            }
            else
            {
                MessageBox.Show("Please enter the same password in the tho boxes", "Password mismatch", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }

        }

        public void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void repeatPassowrdTextBox_TextChanged(object sender, EventArgs e)
        {

        }
    }

    public static class Keys
    {
        public static void GenerateKeys(string fullname, string password)
        {
            GnuPGTool pgpsharp = new GnuPGTool();
            pgpsharp.KeyringFolder = Environment.CurrentDirectory + @"\Keys\";
            Directory.CreateDirectory(Environment.CurrentDirectory + @"\Keys\");
            GenerateKey(fullname, password, Environment.CurrentDirectory + @"\Keys\");

        }

        public static void GenerateKey(string username, string password, string keyStoreUrl)
        {
            IAsymmetricCipherKeyPairGenerator kpg = new RsaKeyPairGenerator();
            kpg.Init(new RsaKeyGenerationParameters(BigInteger.ValueOf(new SecureRandom().Next()), new SecureRandom(), 4096, 8));
            AsymmetricCipherKeyPair kp = kpg.GenerateKeyPair();

            FileStream out1 = new FileInfo(string.Format("{0}secret.asc", keyStoreUrl)).OpenWrite();
            FileStream out2 = new FileInfo(string.Format("{0}pub.asc", keyStoreUrl)).OpenWrite();

            ExportKeyPair(out1, out2, kp.Public, kp.Private, username, password.ToCharArray(), true);

        }<commit_msg>fixed infinite key generation time<commit_after>﻿using System;
using PgpSharp.GnuPG;
using System.Windows.Forms;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.Security;
using System.IO;
using Org.BouncyCastle.Math;
using Org.BouncyCastle.Bcpg.OpenPgp;
using Org.BouncyCastle.Bcpg;

namespace Encrypted_messager
{
    public partial class CreateKeys : Form
    {
        public CreateKeys()
        {
            InitializeComponent();
            this.ControlBox = false;
            MessageBox.Show("It seems that this is the first run. Please create a pair of keys. Fill the form to continue.");
        }

        private void CreateKeys_Load(object sender, EventArgs e)
        {
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (passwordTextBox.Text == repeatPassowrdTextBox.Text)
            {
                MessageBox.Show("The program will now generate the keys. This may take some time. Please wait patiently.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Keys.GenerateKeys(textBox1.Text, passwordTextBox.Text);
                this.Close();
            }
            else
            {
                MessageBox.Show("Please enter the same password in the tho boxes", "Password mismatch", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }

        }

        public void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void repeatPassowrdTextBox_TextChanged(object sender, EventArgs e)
        {

        }
    }

    public static class Keys
    {
        public static void GenerateKeys(string fullname, string password)
        {
            GnuPGTool pgpsharp = new GnuPGTool();
            pgpsharp.KeyringFolder = Environment.CurrentDirectory + @"\Keys\";
            Directory.CreateDirectory(Environment.CurrentDirectory + @"\Keys\");
            GenerateKey(fullname, password, Environment.CurrentDirectory + @"\Keys\");

        }

        public static void GenerateKey(string username, string password, string keyStoreUrl)
        {
            IAsymmetricCipherKeyPairGenerator kpg = new RsaKeyPairGenerator();
            kpg.Init(new RsaKeyGenerationParameters(BigInteger.ValueOf(new SecureRandom().Next(1,999)), new SecureRandom(), 4096, 8));
            AsymmetricCipherKeyPair kp = kpg.GenerateKeyPair();

            FileStream out1 = new FileInfo(string.Format("{0}secret.asc", keyStoreUrl)).OpenWrite();
            FileStream out2 = new FileInfo(string.Format("{0}pub.asc", keyStoreUrl)).OpenWrite();

            ExportKeyPair(out1, out2, kp.Public, kp.Private, username, password.ToCharArray(), true);

        }
{'fraction_non_alphanumeric': 0.08978382147838215, 'fraction_numerical': 0.005927475592747559, 'mean_word_length': 2.4960390006093847, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6792605', 'n_tokens_mistral': 1613, 'n_tokens_neox': 1547, 'n_words': 374}