Exemple #1
0
        /// <summary>
        /// 加密按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDesEncrypt_Click(object sender, EventArgs e)
        {
            string key     = this.tboxDesKey.Text.ToString().Trim();
            string reqData = this.tboxDesReqData.Text.ToString().Trim();

            if (key == "")
            {
                MessageBox.Show("密钥不能为空!");
                return;
            }
            if (key.Length % 8 != 0)
            {
                MessageBox.Show("密钥长度有误!");
                return;
            }
            if (reqData == "")
            {
                MessageBox.Show("数据不能为空!");
                return;
            }
            if (reqData.Length % 8 != 0)
            {
                MessageBox.Show("数据长度有误");
                return;
            }
            string result = DesEncryptUtil.desEncrypt(reqData, key);

            this.tboxDesResult.Text = result;
        }
Exemple #2
0
        /// <summary>
        /// PIN加密-按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPinEncrypt_Click(object sender, EventArgs e)
        {
            string masterKey = this.tboxPinMasterKey.Text.Trim();
            string pinKey    = this.tboxPinKey.Text.Trim();
            string cardNo    = this.tboxPinCardNo.Text.Trim();
            string pin       = this.tboxPinPassword.Text.Trim();

            if (masterKey != "" && masterKey.Length % 8 != 0)
            {
                MessageBox.Show("主密钥长度有误!");
                return;
            }
            if (pinKey == "")
            {
                MessageBox.Show("PIN密钥不能为空!");
                return;
            }
            if (pinKey.Length % 8 != 0)
            {
                MessageBox.Show("PIN密钥长度有误!");
                return;
            }
            if (pin == "")
            {
                MessageBox.Show("密码不能为空!");
                return;
            }

            if (masterKey != "")
            {
                pinKey = DesEncryptUtil.desDecrypt(pinKey, masterKey);
            }

            //带卡号加密
            if (cardNo != "")
            {
                pin = StringUtil.byteToHexString(PinUtil.process(pin, cardNo));
                string result = DesEncryptUtil.desEncrypt(pin, pinKey);
                this.tboxPinResult.Text = result;
            }
            //不带卡号加密
            else
            {
                string result = DesEncryptUtil.desEncrypt(pin, pinKey);
                this.tboxPinResult.Text = result;
            }
        }