コード例 #1
0
        // Add/Update Button
        private void btnAddKey_Click(object sender, EventArgs e)
        {
            string pKey;

            // Get a new key name
            getNewKey.Location      = new Point(this.Location.X + 10, this.Location.Y + 10);
            getNewKey.StartPosition = FormStartPosition.Manual;

            getNewKey.ShowDialog();

            string keyName = getNewKey.newKey;

            if (keyName == String.Empty)
            {
                return;
            }

            // Make sure that the public key is not part of a key pair in the store
            if (File.Exists(keyStorePath + keyName + ".prvkey"))
            {
                MessageBox.Show("Cannot add Public Key because it is part of a Key Pair!", "Public Key Status");
                return;
            }

            // Get a new public key
            getPubKey.Location      = new Point(this.Location.X + 10, this.Location.Y + 10);
            getPubKey.StartPosition = FormStartPosition.Manual;

            getPubKey.ShowDialog();

            string pub = getPubKey.newKey;

            if (pub == String.Empty)
            {
                return;
            }

            // Remove the junk from pasted text
            pKey = crypto.RemoveWhitespace(pub);
            pKey = pKey.Replace("BEGINPUBLICKEY", String.Empty);
            pKey = pKey.Replace("ENDPUBLICKEY", String.Empty);
            pKey = pKey.Replace("-", String.Empty);

            // Store the key pairs
            if (crypto.RSAStorePublicKey(keyStorePath + keyName + ".pubkey", pKey) == 1)
            {
                MessageBox.Show("Failed to store RSA Public Key", "RSA Key Error");
                return;
            }

            updateKeyPairList();
        }
コード例 #2
0
ファイル: frmYourKeys.cs プロジェクト: jamesnearn/textcryptcs
        // Add new Key Pair
        private void btnAddKeyPair_Click(object sender, EventArgs e)
        {
            Tuple <string, string> kp;
            string keyName;

            // Show the GetNewKey dialog
            getNewKey.Location      = new Point(this.Location.X + 10, this.Location.Y + 10);
            getNewKey.StartPosition = FormStartPosition.Manual;

            getNewKey.ShowDialog();
            keyName = getNewKey.newKey;
            if (keyName == String.Empty)
            {
                return;
            }

            // Show the Get Password Dialog
            password2.ShowDialog();
            string password = password2.Password;

            if (password == String.Empty)
            {
                return;
            }

            // Generate RSA Key Pair
            kp = crypto.RSACreateKeyPair();

            // Store the key pairs
            if (crypto.RSAStorePublicKey(keyStorePath + keyName + ".pubkey", kp.Item2) == 1)
            {
                MessageBox.Show("Failed to store RSA Public Key", "RSA Key Error");
                return;
            }
            if (crypto.RSAStorePrivateKey(keyStorePath + keyName + ".prvkey", kp.Item1, password) == 1)
            {
                MessageBox.Show("Failed to store RSA Private Key", "RSA Key Error");
                return;
            }

            MessageBox.Show("Key Pair Added!", "Key Pair Status");
            updateKeyPairList();
        }