資源簡介
使用C#實現加密狗身份驗證源代碼使用C#實現加密狗身份驗證源代碼

代碼片段和文件信息
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;
//Download?by?http://www.codefans.net
using?System.Runtime.InteropServices;
namespace?使用加密狗進行身份驗證
{
????public?partial?class?Form1?:?Form
????{
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????private?void?button1_Click(object?sender?EventArgs?e)
????????{
????????????Dog?dog?=?new?Dog(100);
????????????dog.DogAddr?=?0;
????????????dog.DogBytes?=?6;
????????????dog.ReadDog();
????????????if?(dog.Retcode?==?0)
????????????{
????????????????char[]?chTemp?=?new?char[6];
????????????????for?(int?i?=?0;?i?6;?i++)
????????????????{
????????????????????chTemp[i]?=?(char)dog.DogData[i];
????????????????}
????????????????String?str?=?new?String(chTemp);
????????????????if?(textBox2.Text==str)
????????????????{
????????????????????MessageBox.Show(“OK“);
????????????????}
????????????????else
????????????????{
????????????????????MessageBox.Show(“error“);
????????????????}
????????????}
????????}
????????private?void?button2_Click(object?sender?EventArgs?e)
????????{
????????????Application.Exit();
????????}
????}
}
[StructLayout(LayoutKind.Sequential)]
//這個類用于讀寫加密狗。
public?unsafe?class?Dog
{
????public?uint?DogBytes?DogAddr;??//設置加密狗起始地址
????public?byte[]?DogData;??//設置數據的長度
????public?uint?Retcode;
????[DllImport(“Win32dll.dll“?CharSet?=?CharSet.Ansi)]
????public?static?unsafe?extern?uint?DogRead(uint?idogBytes?uint?idogAddr?byte*?pdogData);
????public?unsafe?Dog(ushort?num)
????{
????????DogBytes?=?num;
????????DogData?=?new?byte[DogBytes];?//設置數據的長度
????}
????public?unsafe?void?ReadDog()
????{
????????fixed?(byte*?pDogData?=?&DogData[0])
????????{
????????????Retcode?=?DogRead(DogBytes?DogAddr?pDogData); //將數據讀出加密狗
????????}
????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????2090??2013-08-08?22:08??okba
?????文件???????5504??2013-08-08?22:08??okba
?????文件???????5814??2013-08-08?22:08??okba
?????文件????????551??2013-08-08?22:08??okba
?????文件???????1398??2013-08-08?22:08??okba
?????文件???????2953??2013-08-08?22:08??okba
?????文件???????5612??2013-08-08?22:08??okba
?????文件???????1118??2013-08-08?22:08??okba
?????文件????????249??2013-08-08?22:08??okba
?????文件???????3861??2013-08-08?22:08??okba
?????文件????????955??2013-08-08?22:08??okba
?????文件??????16896??2013-08-08?22:08??okba
?????目錄??????????0??2013-08-08?22:08??okba
?????目錄??????????0??2013-08-08?22:08??okba
?????目錄??????????0??2013-08-08?22:08??okba
-----------?---------??----------?-----??----
????????????????47001????????????????????15
評論
共有 條評論