Example #1
0
        public CryptionHelper(string key, SupportedAlogrithm alogrithm)
        {
            this.CustomizedKey     = key;
            this.SelectedAlogrithm = alogrithm;

            switch (this.SelectedAlogrithm)
            {
            case SupportedAlogrithm.AES:
                cryptor = new AESCryption(this.CustomizedKey);
                break;

            case SupportedAlogrithm.RSA:
                cryptor = new RSACryption(this.CustomizedKey);
                break;

            case SupportedAlogrithm.TripleDES:
                cryptor = new TripleDESCryption(this.CustomizedKey);
                break;
            }
        }
Example #2
0
        private void comboAlogrithms_SelectedIndexChanged(object sender, EventArgs e)
        {
            this._selectedAlogrithm = (SupportedAlogrithm)Enum.Parse(typeof(SupportedAlogrithm), this.comboAlogrithms.SelectedItem.ToString());
            if (AlogrithmKeyPair.Keys.Contains(this._selectedAlogrithm))
            {
                this._isKeyRequired = AlogrithmKeyPair[this._selectedAlogrithm];
            }

            this.txtKey.Clear();
            this.btnImportKey.Enabled  = this._isKeyRequired;
            this.cbKeyRequired.Checked = this._isKeyRequired;
            this.txtKey.ReadOnly       = !this._isKeyRequired;

            if (this._selectedAlogrithm == SupportedAlogrithm.RSA)
            {
                string message = string.Empty;

                if (this._inputOption == InputOption.eFile)
                {
                    message = string.Format("RSA is not supported yet for File Input!\nPlease try a different alogrithm.");
                    MessageBox.Show(message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    message = string.Format("RSA needs Public/Private keys for Encryption/Decryption.\nDo you want to Generate and Save them?");
                    DialogResult dialogResult = MessageBox.Show(message, "NOTICE", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (dialogResult == DialogResult.Yes)
                    {
                        // generate public and private keys
                        RSACryption.GenerateRSAKeys(CryptionHelper.PRIVATE_KEY_PATH, CryptionHelper.PUBLIC_KEY_PATH);
                        message = string.Format("PublicKey.xml and PrivateKey.xml are saved at: \n{0}", Environment.GetFolderPath(Environment.SpecialFolder.Desktop));
                        MessageBox.Show(message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
        }