zoukankan      html  css  js  c++  java
  • asp.net中加密狗 代码

    程序代码 程序代码
    using ...System.Runtime.InteropServices ;
    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);

        [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); //将数据写入加密狗

            }

        }

    }


    向加密狗里边写入数据:Dog d=new Dog(10);d.DogAddr=0;for(int i=0;i<d.DogData.length;i++)d.DogData[i]=i;d.WriteDog();

    读取加密狗里边的数据:Dog d=new Dog(10);byte[] b;d.ReadDog();b=new byte[d.DogData.length];

    for (int i=0;i<d.DogData.lengh;i++)b[i]=d.DogData[i];

    extern:表明我们用到的该方法是在外部声明的,即该方法是在win32dll.dll程序集里边;

    unsafe:表明该加密狗类是不安全的.

  • 相关阅读:
    Redis持久化——AOF日志
    设计原则:接口隔离原则(ISP)
    设计原则:里式替换原则(LSP)
    新入职一家公司如何快速进入工作状态
    又是一年毕业季——如何入坑程序员
    设计原则:开闭原则(OCP)
    设计原则:单一职责(SRP)原则
    Redis持久化——内存快照(RDB)
    工作中应该如何管理自己的情绪?
    如何成为一个精力充沛的程序员——掌控
  • 原文地址:https://www.cnblogs.com/sontin/p/1929801.html
Copyright © 2011-2022 走看看