示例#1
0
        public byte[] GetBytes(object obj, int length)
        {
            String str = obj as String;

            if (String.IsNullOrEmpty(str))
            {
                return(ByteUtil.Malloc(length));
            }

            return(ArrayUtil.CopyFrom(Encoding.UTF8.GetBytes(str), length));
        }
示例#2
0
        private DongleUserInfoStru CreateUserInfoStru(DongleUserInfo keyInfo)
        {
            DongleUserInfoStru stru = new DongleUserInfoStru();

            stru.DongleType = (byte)keyInfo.DongleType;
            stru.UserId     = ArrayUtil.CopyFrom(this.encoder.GetBytes(keyInfo.UserId), 6);
            stru.UserName   = ArrayUtil.CopyFrom(this.encoder.GetBytes(keyInfo.UserName), 64);
            stru.CreateDate = ArrayUtil.CopyFrom(this.encoder.GetBytes(keyInfo.CreateDate), 14);
            stru.Operator   = ArrayUtil.CopyFrom(this.encoder.GetBytes(keyInfo.Operator), 3);
            return(stru);
        }
示例#3
0
        /// <summary>
        /// atqa : Answer To Request, Type A
        ///	sak : Select Acknowledge
        /// </summary>
        public bool Select(out byte[] sn)
        {
            uint snLen = 0;

            byte[] buffer = ByteUtil.Malloc(16);

            //Reset();
            if (dc_card_n(this.hReader, 0x00, ref snLen, buffer) != SUCC)
            {
                sn = null;
                return(false);
            }
            sn = ArrayUtil.CopyFrom(buffer, (int)snLen);
            return(true);
        }
示例#4
0
        private bool Encrypt(byte[] plain, out byte[] cipher)
        {
            cipher = null;

            if (!IsActive())
            {
                logger.Debug("Create authen key failed -- no dongle opened!");
                return(false);
            }

            int len = (plain.Length % 16 == 0) ? plain.Length : (plain.Length / 16 + 1) * 16;

            // fill zero
            cipher             = ArrayUtil.CopyFrom <byte>(plain, len);
            this.lastErrorCode = Dongle_TDES(this.hDongle, DongleConst.USER_ROOT_KEY_DESCRIPTOR, 0, cipher, cipher, (uint)len);
            logger.Debug(String.Format("plain = [ {0} ], cipher = [ {1} ]", BitConverter.ToString(plain), BitConverter.ToString(cipher)));

            return(IsSucc);
        }
示例#5
0
 private byte[] GetBytes(byte[] obj, int length)
 {
     return(ArrayUtil.CopyFrom(obj, length));
 }