示例#1
0
        private void Initialize()
        {
            uint size = 0;
            uint ret  = S4Enum(null, ref size);

            Debug.Assert(0x11 == ret);

            si  = new SENSE4_CONTEXT[size / Marshal.SizeOf(typeof(SENSE4_CONTEXT))];
            ret = S4Enum(si, ref size);
            Debug.Assert(0x00 == ret);
        }
示例#2
0
 private static extern uint S4Execute(ref SENSE4_CONTEXT s4Ctx, string FileID, byte[] InBuffer,
                                      uint InbufferSize, byte[] OutBuffer, uint OutBufferSize, ref uint BytesReturned);
示例#3
0
 private static extern uint S4WriteFile(ref SENSE4_CONTEXT s4Ctx, string FileID, uint Offset,
                                        byte[] Buffer, uint BufferSize, uint FileSize, ref uint BytesWritten, uint Flags,
                                        uint FileType);
示例#4
0
 private static extern uint S4ChangePin(ref SENSE4_CONTEXT s4Ctx, byte[] OldPin, uint OldPinLen,
                                        byte[] NewPin, uint NewPinLen, uint PinType);
示例#5
0
 private static extern uint S4VerifyPin(ref SENSE4_CONTEXT s4Ctx, byte[] Pin, uint PinLen, uint PinType);
示例#6
0
 private static extern uint S4EraseDir(ref SENSE4_CONTEXT s4Ctx, string DirID);
示例#7
0
 private static extern uint S4ChangeDir(ref SENSE4_CONTEXT s4Ctx, string Path);
示例#8
0
 private static extern uint S4CreateDir(ref SENSE4_CONTEXT s4Ctx, string DirID, uint DirSize, uint Flags);
示例#9
0
 private static extern uint S4Control(ref SENSE4_CONTEXT s4Ctx, uint ctlCode, byte[] inBuff,
                                      uint inBuffLen, byte[] outBuff, uint outBuffLen, ref uint BytesReturned);
示例#10
0
 private static extern uint S4Close(ref SENSE4_CONTEXT s4_context);
示例#11
0
 private static extern uint S4Open(ref SENSE4_CONTEXT s4_context);
示例#12
0
        public static bool Verification(out string strMsg)
        {
            if (IntPtr.Size == 8)
            {
                return(VerificationX64(out strMsg));
            }
            try
            {
                strMsg = string.Empty;

                uint size = 0;

                byte[] inBuffer = new byte[512];

                byte[] outBuffer = new byte[256];

                byte[] wModID = new byte[2];

                byte[] wNewtimeouts = new byte[2];

                uint BytesReturned = 0;

                // 查找网络锁,配置文件在同目录下:e4ncli.ini
                uint             ret = S4Enum(null, ref size);
                SENSE4_CONTEXT[] si  = new SENSE4_CONTEXT[size / Marshal.SizeOf(typeof(SENSE4_CONTEXT))];
                ret = S4Enum(si, ref size);
                if (ret != S4_SUCCESS)
                {
                    strMsg = "04 - 加密锁启动失败!代码:" + ret.ToString();
                    //MessageDxUtil.ShowMsg("04 - 加密锁启动失败!代码:" + ret.ToString(), MessageDxUtil.MsgType.Warning);
                    return(false);
                }

                int siIndex = -1;
                //验证加密锁的ID
                for (int i = 0; i < si.Length; i++)
                {
                    var siList = new List <byte>(si[i].bAtr);

                    siList.RemoveRange(0, int.Parse(si[i].dwAtrLen.ToString()) - 8);

                    var sSer = Encoding.Default.GetString(siList.ToArray());

                    if (sSer.Trim().IndexOf("EAct") != -1)
                    {
                        siIndex = i;
                        break;
                    }
                }

                if (siIndex == -1)
                {
                    strMsg = "04 - 没有发现EAct系统的加密狗!";
                    //MessageDxUtil.ShowMsg("04 - 没有发现EAct系统的加密狗!", MessageDxUtil.MsgType.Warning);
                    return(false);
                }

                // 打开网络锁
                ret = S4Open(ref si[siIndex]);
                if (ret != S4_SUCCESS)
                {
                    strMsg = "04 - 加密锁网络访问失败!代码:" + ret.ToString();
                    //MessageDxUtil.ShowMsg("04 - 加密锁网络访问失败!代码:" + ret.ToString(), MessageDxUtil.MsgType.Warning);
                    return(false);
                }

                // 获取授权
                wModID[0] = 0x01;
                wModID[1] = 0x00;
                ret       = S4Control(ref si[siIndex], S4_GET_LICENSE, wModID, 2, null, 0, ref BytesReturned);
                if (ret != S4_SUCCESS)
                {
                    S4Close(ref si[siIndex]);
                    strMsg = "04 - 请插入加密锁或检查加密锁服务是否启动!代码:" + ret.ToString();
                    //MessageDxUtil.ShowMsg("04 - 请插入加密锁或检查加密锁服务是否启动!代码:" + ret.ToString(), MessageDxUtil.MsgType.Warning);
                    return(false);
                }
                return(true);
            }

            catch (Exception ex)
            {
                strMsg = "04 - 加密锁验证失败!错误:" + ex.Message.ToString();
                //MessageDxUtil.ShowMsg("04 - 加密锁验证失败!错误:" + ex.Message.ToString(), MessageDxUtil.MsgType.Warning);
                return(false);
            }
        }