目录
进口车电子信息单二维码解密
效果
二维码信息
QzcOcj0yNsb9cVZsGoZKBOrBbn4RJ6O0N4q9/R10ANBvPgWt1vO75YmnWHsImhQUluNYC/OUYwWiO2IljHAhPmSAm3BieWZpXwi1IGWzLKAkRGkTUpqhT2pwEhkbMKcFsfsBfxh9MT1KRy2Ya+DvLKwL+vOVHp7ZJUh4DdDof6GBGfsvamTuZ/gQjgIdiuDqf+mo2dKFJ+hy9927A3T5xMEWjBpclbKnrTIF8BpTADCop1xBzuZ0nVbiQQn3HfMS+qZiHwYeGRwIYeVqEYWt3srrMsxOhBIHKh16qfk8gws=
解密后信息
测试企业名称#%测试品牌#%测试车辆名称#%TESTCLXH#%LVBJ1234567890123#%TESTFDJH#%12345678901234#%黄色/黑白花#%中华人民共和国海关货物进口证明书编号#%2012-12-31#%2012-12-31#%2012-12-31
代码
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.Runtime.InteropServices;
using System.Diagnostics;
namespace 进口车_调用Demo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
const string DllName = "ImVehDec.dll";
[DllImport(DllName, EntryPoint = "getmcode", CallingConvention = CallingConvention.Cdecl)]
public extern static int getmcode(string key, StringBuilder mcode, StringBuilder msg);
[DllImport(DllName, EntryPoint = "verify", CallingConvention = CallingConvention.Cdecl)]
public extern static int verify(string key, string rcode, StringBuilder msg);
[DllImport(DllName, EntryPoint = "dec", CallingConvention = CallingConvention.Cdecl)]
public extern static int dec(string key, IntPtr code, int codeLen, string rcode, StringBuilder result, StringBuilder msg);
string key = "A2E1C262-7D08-4C5A-A91C-CA691F684275";
private void Form1_Load(object sender, EventArgs e)
{
button1_Click(null, null);
}
private void button1_Click(object sender, EventArgs e)
{
StringBuilder mcode = new StringBuilder(64);
StringBuilder msg = new StringBuilder(512);
int res = getmcode(key, mcode, msg);
if (res == 0)
{
txtmcode.Text = mcode.ToString();
}
else
{
MessageBox.Show("获取机器码错误:" + msg.ToString());
}
}
private void button3_Click(object sender, EventArgs e)
{
string rcode = txtrcode.Text;//注册码
StringBuilder msg = new StringBuilder(512);
int res = verify(key, rcode, msg);
if (res == 0)
{
MessageBox.Show("校验正确");
}
else
{
MessageBox.Show("校验失败:" + msg.ToString());
}
}
private void button2_Click(object sender, EventArgs e)
{
string codeStr = txtcode.Text;//二维码信息
string rcode = txtrcode.Text;//注册码
StringBuilder result = new StringBuilder(2048);
StringBuilder msg = new StringBuilder(512);
Stopwatch stopwatch = new Stopwatch();
if (codeStr.Contains("●"))
{
codeStr = codeStr.Replace("●", "");
}
if (codeStr.Contains("?"))
{
codeStr = codeStr.Replace("?", "");
}
byte[] code = null;
try
{
code = System.Convert.FromBase64String(codeStr);
}
catch (Exception ex)
{
MessageBox.Show("二维码信息不正确");
return;
}
IntPtr ptr = Marshal.AllocHGlobal(code.Length);
Marshal.Copy(code, 0, ptr, code.Length);
stopwatch.Start();
int res = dec(key, ptr, code.Length, rcode, result, msg);
if (res == 0)
{
txtresult.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\r\n";
txtresult.Text += "耗时:" + stopwatch.ElapsedMilliseconds + "毫秒\r\n";
txtresult.Text += result.ToString();
}
else
{
txtresult.Text = "解密错误:" + msg.ToString();
}
// 释放内存
Marshal.FreeHGlobal(ptr);
}
}
}
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.Runtime.InteropServices;
using System.Diagnostics;
namespace 进口车_调用Demo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
const string DllName = "ImVehDec.dll";
[DllImport(DllName, EntryPoint = "getmcode", CallingConvention = CallingConvention.Cdecl)]
public extern static int getmcode(string key, StringBuilder mcode, StringBuilder msg);
[DllImport(DllName, EntryPoint = "verify", CallingConvention = CallingConvention.Cdecl)]
public extern static int verify(string key, string rcode, StringBuilder msg);
[DllImport(DllName, EntryPoint = "dec", CallingConvention = CallingConvention.Cdecl)]
public extern static int dec(string key, IntPtr code, int codeLen, string rcode, StringBuilder result, StringBuilder msg);
string key = "A2E1C262-7D08-4C5A-A91C-CA691F684275";
private void Form1_Load(object sender, EventArgs e)
{
button1_Click(null, null);
}
private void button1_Click(object sender, EventArgs e)
{
StringBuilder mcode = new StringBuilder(64);
StringBuilder msg = new StringBuilder(512);
int res = getmcode(key, mcode, msg);
if (res == 0)
{
txtmcode.Text = mcode.ToString();
}
else
{
MessageBox.Show("获取机器码错误:" + msg.ToString());
}
}
private void button3_Click(object sender, EventArgs e)
{
string rcode = txtrcode.Text;//注册码
StringBuilder msg = new StringBuilder(512);
int res = verify(key, rcode, msg);
if (res == 0)
{
MessageBox.Show("校验正确");
}
else
{
MessageBox.Show("校验失败:" + msg.ToString());
}
}
private void button2_Click(object sender, EventArgs e)
{
string codeStr = txtcode.Text;//二维码信息
string rcode = txtrcode.Text;//注册码
StringBuilder result = new StringBuilder(2048);
StringBuilder msg = new StringBuilder(512);
Stopwatch stopwatch = new Stopwatch();
if (codeStr.Contains("●"))
{
codeStr = codeStr.Replace("●", "");
}
if (codeStr.Contains("?"))
{
codeStr = codeStr.Replace("?", "");
}
byte[] code = null;
try
{
code = System.Convert.FromBase64String(codeStr);
}
catch (Exception ex)
{
MessageBox.Show("二维码信息不正确");
return;
}
IntPtr ptr = Marshal.AllocHGlobal(code.Length);
Marshal.Copy(code, 0, ptr, code.Length);
stopwatch.Start();
int res = dec(key, ptr, code.Length, rcode, result, msg);
if (res == 0)
{
txtresult.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\r\n";
txtresult.Text += "耗时:" + stopwatch.ElapsedMilliseconds + "毫秒\r\n";
txtresult.Text += result.ToString();
}
else
{
txtresult.Text = "解密错误:" + msg.ToString();
}
// 释放内存
Marshal.FreeHGlobal(ptr);
}
}
}