예제 #1
0
        /// <summary>
        /// 加密,解密
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDES_Click(object sender, EventArgs e)
        {
            string btnName = (sender as Button).Text;

            switch (btnName)
            {
            case "DES加密":
                SetContent(this.txtValue, new Func <string, string, string>(EncryptHelper.Encrypt), this.txtKey.Text.Trim(), this.txtParam.Text.Trim());
                break;

            case "DES解密":
                SetContent(this.txtValue, new Func <string, string, string>(EncryptHelper.Decrypt), this.txtKey.Text.Trim(), this.txtParam.Text.Trim());
                break;

            case "RSA加密":
            {
                SetContent(this.txtValue, new Func <string, string, string>(RSANewHelper.Encrypt), this.txtKey.Text.Trim(), this.txtPublicKey.Text.Trim());
            }
            break;

            case "RSA解密":
            {
                SetContent(this.txtValue, new Func <string, string, string>(RSANewHelper.Decrypt), this.txtKey.Text.Trim(), this.txtPrivateKey.Text.Trim());
            }
            break;

            case "生成公钥私钥":
                string[] keys = RSAHelper.GenerateKeys();
                this.txtPrivateKey.Text = keys[0];
                this.txtPublicKey.Text  = keys[1];
                break;

            case "MD5":
                SetContent(this.txtValue, new Func <string, string>(EncryptHelper.GetMD5), this.txtKey.Text.Trim());
                break;

            case "SHA1":
                SetContent(this.txtValue, new Func <string, string>(EncryptHelper.GetSHA1), this.txtKey.Text.Trim());
                break;

            case "随机AES密钥":
                SetContent(this.txtParam, new Func <int, string>(AESHelper.GetIv), 16);
                break;

            case "AES加密":
                SetContent(this.txtValue, new Func <string, string, string>(AESHelper.AESEncrypt), this.txtKey.Text.Trim(), this.txtParam.Text.Trim());
                break;

            case "AES解密":
                SetContent(this.txtValue, new Func <string, string, string>(AESHelper.AESDecrypt), this.txtKey.Text.Trim(), this.txtParam.Text.Trim());
                break;
            }
        }