Example #1
0
        public override ReturnValueInfo WriteUKeyContent(string newPassword)
        {
            ReturnValueInfo returnValue = new ReturnValueInfo();
            int             rtn         = 0;
            int             address     = 0; //加密锁读取数据的起始位置,可以自定义加密锁读取数据的起始位置,最大为1024

            byte[] pBuffer = new byte[this.UKeyContentLenght];

            //Start*************************当新密码的长度比所定义的长度小时,在新密码后面加上足够长的“F”字符串***************************************************
            int newPasswordLenght = 0;

            if (newPassword.Trim().Length < this.UKeyContentLenght)
            {
                int    difference       = this.UKeyContentLenght - newPasswordLenght;
                string differenceString = string.Empty;

                for (int i = 0; i < difference; i++)
                {
                    differenceString += "F";
                }

                newPassword = newPassword.Trim() + differenceString;
            }
            //End*************************当新密码的长度比所定义的长度小时,在新密码后面加上足够长的“F”字符串***************************************************

            pBuffer = Encoding.GetEncoding("gb2312").GetBytes(newPassword);

            rtn = NT119API.NTWrite(address, this.UKeyContentLenght, pBuffer);//存储区数据写入,如果返回值为 0,表示数据写入成功。
            //如果返回值不为0,则可以通过返回值Rtn查看错误代码
            if (rtn != 0)
            {
                returnValue.IsSuccess   = false;
                returnValue.MessageText = "写入内容失败!";
            }
            else
            {
                returnValue.IsSuccess   = true;
                returnValue.MessageText = "写入内容成功!";
            }

            return(returnValue);
        }
Example #2
0
        public override ReturnValueInfo ReadUKeyContent()
        {
            ReturnValueInfo returnValue = new ReturnValueInfo();
            int             rtn         = 0;
            int             address     = 0;                   //加密锁读取数据的起始位置,可以自定义加密锁读取数据的起始位置,最大为1024

            byte[] pBuffer = new byte[this.UKeyContentLenght]; //存储区数据读取,如果返回值为 0,表示数据写入成功。
            //如果返回值不为0,则可以通过返回值Rtn查看错误代码

            rtn = NT119API.NTRead(address, this.UKeyContentLenght, pBuffer);
            if (rtn != 0)
            {
                returnValue.IsSuccess   = false;
                returnValue.MessageText = "读取密码失败!";
            }
            else
            {
                returnValue.IsSuccess   = true;
                returnValue.MessageText = System.Text.Encoding.Default.GetString(pBuffer).Trim();
            }

            return(returnValue);
        }