예제 #1
0
        private void btnGenerateKeys_Click(object sender, EventArgs e)
        {
            if (!IsTbEmpty(tbP, tbQ))
            {
                int P = Convert.ToInt32(tbP.Text);
                int Q = Convert.ToInt32(tbQ.Text);

                RSAKeys rsaKeys = RSAKeyPairGenerator.GenerateKeysPair(P, Q);

                tbPublicKeyGenerated.Text  = rsaKeys.PublicKeys.ToString();
                tbPrivateKeyGenerated.Text = rsaKeys.PrivateKeys.ToString();

                tbDecryptKey.Text = rsaKeys.PrivateKeys.ToString();
                tbEncryptKey.Text = rsaKeys.PublicKeys.ToString();
            }
        }
예제 #2
0
        public static RSAKeys GenerateKeysPair(int p, int q)
        {
            RSAKeys keys = new RSAKeys();
            KeyValuePair <int, int> publicKeys;
            KeyValuePair <int, int> privateKeys;
            int n         = p * q;
            int eulerFunc = (p - 1) * (q - 1);
            int e         = findComprimeNumber(eulerFunc);

            publicKeys      = new KeyValuePair <int, int>(e, n);
            keys.PublicKeys = publicKeys;

            int d = CountDValue(eulerFunc, e);

            privateKeys      = new KeyValuePair <int, int>(d, n);
            keys.PrivateKeys = privateKeys;

            return(keys);
        }