/// <summary> /// 解密按钮事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDesDecrypt_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.desDecrypt(reqData, key); this.tboxDesResult.Text = result; }
/// <summary> /// PIN加密-解密按钮事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnPinDecrypt_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 != "") { //解密 string pinBlock = DesEncryptUtil.desDecrypt(pin, pinKey); byte[] pinBlockClearText = PinUtil.reverse(cardNo, pinBlock); string result = StringUtil.byteToHexString(pinBlockClearText); this.tboxPinResult.Text = result; } //不带卡号加密 else { string result = DesEncryptUtil.desDecrypt(pin, pinKey); this.tboxPinResult.Text = result; } }
/// <summary> /// X9.19 MAC计算按钮点击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnMacEncryptX919_Click(object sender, EventArgs e) { string masterKey = this.tboxMacMasterKey.Text.Trim(); string macKey = this.tboxMacMacKey.Text.Trim(); string reqData = this.tboxMacReqData.Text.Trim(); if (masterKey != "" && masterKey.Length % 8 != 0) { MessageBox.Show("主密钥长度有误!"); return; } if (macKey == "") { MessageBox.Show("MAC密钥不能为空!"); return; } if (macKey.Length % 8 != 0 || macKey.Length < 32) { MessageBox.Show("MAC密钥长度有误!"); return; } if (reqData == "") { MessageBox.Show("数据不能为空!"); return; } if (masterKey != "") { macKey = DesEncryptUtil.desDecrypt(macKey, masterKey); } reqData = reqData.Replace(" ", ""); reqData = reqData.Replace("\n", ""); reqData = reqData.Replace("\t", ""); reqData = reqData.Replace("\r", ""); string result = ANSIX919.getMac(reqData, macKey); this.tboxMacResult.Text = result; }