礼品卡卡信息解密WindowsUI版

本程序适用于聚合礼品卡接口:http://www.juhe.cn/docs/api/id/231

前台界面代码:

namespace GiftCardApplication
{
    partial class Form1
    {
        /// <summary>
        /// 必需的设计器变量。
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// 清理所有正在使用的资源。
        /// </summary>
        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows 窗体设计器生成的代码

        /// <summary>
        /// 设计器支持所需的方法 - 不要
        /// 使用代码编辑器修改此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.tb_no = new System.Windows.Forms.TextBox();
            this.tb_pwd = new System.Windows.Forms.TextBox();
            this.button1 = new System.Windows.Forms.Button();
            this.label3 = new System.Windows.Forms.Label();
            this.tb_usr = new System.Windows.Forms.TextBox();
            this.label4 = new System.Windows.Forms.Label();
            this.tb_result = new System.Windows.Forms.TextBox();
            this.SuspendLayout();
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(58, 76);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(77, 12);
            this.label1.TabIndex = 0;
            this.label1.Text = "礼品卡卡号:";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(58, 118);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(77, 12);
            this.label2.TabIndex = 1;
            this.label2.Text = "礼品卡卡密:";
            // 
            // tb_no
            // 
            this.tb_no.Location = new System.Drawing.Point(139, 73);
            this.tb_no.Name = "tb_no";
            this.tb_no.Size = new System.Drawing.Size(298, 21);
            this.tb_no.TabIndex = 2;
            // 
            // tb_pwd
            // 
            this.tb_pwd.Location = new System.Drawing.Point(139, 115);
            this.tb_pwd.Name = "tb_pwd";
            this.tb_pwd.Size = new System.Drawing.Size(298, 21);
            this.tb_pwd.TabIndex = 3;
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(209, 153);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(126, 35);
            this.button1.TabIndex = 5;
            this.button1.Text = "解密";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(58, 216);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(77, 12);
            this.label3.TabIndex = 6;
            this.label3.Text = "礼品卡信息:";
            // 
            // tb_usr
            // 
            this.tb_usr.Location = new System.Drawing.Point(139, 29);
            this.tb_usr.Name = "tb_usr";
            this.tb_usr.Size = new System.Drawing.Size(298, 21);
            this.tb_usr.TabIndex = 1;
            // 
            // label4
            // 
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(58, 32);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(53, 12);
            this.label4.TabIndex = 7;
            this.label4.Text = "用户名:";
            // 
            // tb_result
            // 
            this.tb_result.AllowDrop = true;
            this.tb_result.Location = new System.Drawing.Point(139, 213);
            this.tb_result.Multiline = true;
            this.tb_result.Name = "tb_result";
            this.tb_result.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
            this.tb_result.Size = new System.Drawing.Size(298, 130);
            this.tb_result.TabIndex = 4;
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(512, 377);
            this.Controls.Add(this.tb_usr);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.tb_result);
            this.Controls.Add(this.tb_pwd);
            this.Controls.Add(this.tb_no);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MaximizeBox = false;
            this.Name = "Form1";
            this.Text = "聚合礼品卡解密 Windows版";
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.TextBox tb_no;
        private System.Windows.Forms.TextBox tb_pwd;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.TextBox tb_usr;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.TextBox tb_result;
    }
}

后台代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography;
using System.IO;
using System.Diagnostics;

namespace GiftCardApplication
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 礼品卡解密
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (tb_usr.Text.Trim().ToString() == "")
                {
                    MessageBox.Show("用户名不能为空!", "提示");
                }
                else if (tb_no.Text.Trim().ToString() == "")
                {
                    MessageBox.Show("礼品卡卡号不能为空!", "提示");
                }
                else if (tb_pwd.Text.Trim().ToString() == "")
                {
                    MessageBox.Show("礼品卡卡密不能为空!", "提示");
                }

                else
                {
                    //密钥是您的用户名的前8位,不足8位则用数字0补齐
                    string key = this.tb_usr.Text.Trim().PadRight(8, '0').Substring(0, 8);

                    //礼品卡卡号
                    string no = this.tb_no.Text.Trim().ToString();
                    
                    //礼品卡密码
                    string pwd = this.tb_pwd.Text.Trim().ToString();

                    this.tb_result.Text += "卡号:" + DesDecrypt(no, key) + "\r\n";
                    this.tb_result.Text += "卡密:" + DesDecrypt(pwd, key) + "\r\n";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("礼品卡卡号或礼品卡卡密错误,请重试!", "提示");
            }

        }

        /// <summary>
        /// 解密字符串
        /// </summary>
        /// <param name="strText">密文</param>
        /// <param name="decryptKey">密钥</param>
        /// <returns></returns>
        static string DesDecrypt(string strText, string decryptKey)
        {
            string outString = "";
            try
            {
                byte[] byKey = null;
                byte[] IV = Encoding.Default.GetBytes(decryptKey);
                byte[] inputByteArray = new Byte[strText.Length];

                byKey = System.Text.Encoding.UTF8.GetBytes(decryptKey.Substring(0, decryptKey.Length));
                DESCryptoServiceProvider des = new DESCryptoServiceProvider();
                des.Mode = CipherMode.ECB;
                inputByteArray = Convert.FromBase64String(strText);
                MemoryStream ms = new MemoryStream();
                CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(byKey, IV), CryptoStreamMode.Write);
                cs.Write(inputByteArray, 0, inputByteArray.Length);
                cs.FlushFinalBlock();
                System.Text.Encoding encoding = new System.Text.UTF8Encoding();
                outString = encoding.GetString(ms.ToArray());
            }
            catch (Exception)
            {
                outString = "null";
            }
            return outString;
        }
    }
}




登录 后可发表评论

    最新发布
    聚合数据©版权所有