賽孚耐(SafeNet)加密狗
購買鏈接:https://item.jd.com/21653904499.html
需求:
加密狗作用:如果未插入加密狗,則程序無法運行。
我們會給每個客戶一個加密狗,希望通過加密狗編號自動對應客戶。
加密狗制作流程:
1. 安裝《超級加密狗工具包》,通過開發商向導安裝函數庫。
2. 插入加密狗driver和開發狗master
3. 使用《外殼加密工具》加密程序
4. 使用《授權管理工具》授權加密狗有效期
官方給的API調用文檔,太復雜了,看得人暈頭轉向。整理下備忘。
using SuperDog; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Windows.Forms; namespace WinFrmTest { public partial class Form1 : Form { // C:\Program Files (x86)\Gemalto\SuperDog\2.5\VendorCodes\FFWWC.hvc const string vcode = "xxxx"; public Form1() { InitializeComponent(); } private void showInfo(string str) { textBox1.AppendText(str + System.Environment.NewLine); } private void button1_Click(object sender, EventArgs e) { DogStatus res = DogStatus.StatusOk; showInfo("獲取加密狗信息"); string a1 = ""+ "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + "<dogscope/>"; string a2 = "" + "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + "<dogformat root=\"dog_info\">" + " <dog>" + " <attribute name=\"id\" />" + " <attribute name=\"type\" />" + " <feature>" + " <attribute name=\"id\" />" + " </feature>" + " </dog>" + "</dogformat>"; string info = ""; res = Dog.GetInfo(a1, a2, vcode, ref info); if (res != DogStatus.StatusOk) { showInfo("錯誤:" + res.ToString()); return; } showInfo(info); using (var dog = new Dog(new DogFeature(DogFeature.FromFeature(0).Feature))) { showInfo("驗證加密狗"); res = dog.Login(vcode); if (res != DogStatus.StatusOk) { showInfo("錯誤:" + res.ToString()); } else { showInfo("獲取時間"); DateTime dt = new DateTime(); dog.GetTime(ref dt); showInfo(dt.AddHours(8).ToString()); } } } private void button2_Click(object sender, EventArgs e) { textBox1.Text = ""; } } }