.net密码写入与读出加密狗

 时间:2024-10-12 18:59:53

1、新建一个项目,命名随便,主窗体设置为Dog

.net密码写入与读出加密狗

3、在准备操作之前,要应用系统的一些方法。代码如下: public uint DogB鲻戟缒男ytes, 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); [DllImport("Win32dll.dll", CharSet = CharSet.Ansi)] public static unsafe extern uint DogWrite(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);  //将数据读出加密狗 } } public unsafe void WriteDog() { fixed (byte* pDogData = &DogData[0]) { Retcode = DogWrite(DogBytes, DogAddr, pDogData); //将数据写入加密狗 } }

.net密码写入与读出加密狗

5、同样双击button2,添加 Dog dog = new Dog(100); dog.DogAddr = 0; dog.DogBytes = 10; dog.ReadDog(); if (dog.Retcode == 0) //开始读加密狗数据 { char[] chTemp = new char[textBox1.Text.Length]; for (int i = 0; i < textBox1.Text.Length; i++) { chTemp[i] = (char)dog.DogData[i]; } String str = new String(chTemp); textBox2.Text = str; } else { textBox2.Text = "2:" + dog.Retcode; } textBox1.ReadOnly = false; button2.Enabled = false; button1.Enabled = true;

.net密码写入与读出加密狗

6、记得把第一步骤的方法封装成dog类给予调用。编译通过实现。

  • win10升级版本后AutoCAD2013出现闪退的解决办法
  • Win10怎么样禁止用户安装软件 如何限制安装应用
  • 梦幻新诛仙死亡沼泽奇缘任务怎么做
  • 如何快速还原系统,还能保证原来软件能用?
  • 如何通过MSDN下载微软官方的软件
  • 热门搜索
    周庄旅游攻略 大庆旅游 旅游规划设计 世界旅游景点 贵州旅游路线 旅游信息 墨西哥旅游 南京 旅游 淄博旅游景点 惠州旅游景点大全