Beispiel #1
0
        public unsafe static string EncodeBuffer(void *src, int buffSize)
        {
            string result;

            byte[] EncBuf  = new byte[BUFFERSIZE];
            byte[] TempBuf = new byte[BUFFERSIZE];
            byte[] data    = new byte[buffSize];
            fixed(byte *pb = data)
            {
                for (int i = 0; i < buffSize; i++)
                {
                    *(pb + i) = *((byte *)src + i);
                }
            }

            if (buffSize < BUFFERSIZE)
            {
                Array.Copy(data, 0, TempBuf, 0, buffSize);
                int DestLen = Encode6BitBuf(TempBuf, EncBuf, buffSize, BUFFERSIZE);
                fixed(byte *pb = EncBuf)
                {
                    result = HUtil32.SBytePtrToString((sbyte *)pb, 0, DestLen);
                }
            }
            else
            {
                result = "";
            }
            return(result);
        }
Beispiel #2
0
 public override string ToString()
 {
     fixed(sbyte *pb = this.Name)
     {
         return(HUtil32.SBytePtrToString(pb, 0, this.NameLen));
     }
 }
Beispiel #3
0
        /// <summary>
        /// 加密字符串
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public unsafe static string EncodeString(string str)
        {
            string result;

            byte[] EncBuf  = new byte[BUFFERSIZE];
            byte[] bSrc    = HUtil32.StringToByteAry(str);
            int    DestLen = Encode6BitBuf(bSrc, EncBuf, bSrc.Length, BUFFERSIZE);

            fixed(byte *pb = EncBuf)
            {
                result = HUtil32.SBytePtrToString((sbyte *)pb, 0, DestLen);
            }

            return(result);
        }
Beispiel #4
0
        /// <summary>
        /// 解密Byte数组
        /// </summary>
        /// <param name="Src"></param>
        /// <param name="Buf"></param>
        /// <param name="bufsize"></param>
        /// <returns></returns>
        public unsafe static string DecodeBuffer(string Src, byte[] Buf, int bufsize)
        {
            string result;

            byte[] EncBuf = new byte[BUFFERSIZE];
            byte[] bSrc   = System.Text.Encoding.Default.GetBytes(Src);
            int    nLen   = Decode6BitBuf(bSrc, EncBuf, bSrc.Length, BUFFERSIZE);

            fixed(byte *pb = EncBuf)
            {
                result = HUtil32.SBytePtrToString((sbyte *)pb, 0, nLen);
            }

            return(result);
        }
Beispiel #5
0
        /// <summary>
        /// 加密消息
        /// </summary>
        /// <param name="sMsg"></param>
        /// <returns></returns>
        public unsafe static string EncodeMessage(TDefaultMessage sMsg)
        {
            string result = string.Empty;

            byte[] EncBuf  = new byte[BUFFERSIZE];
            byte[] TempBuf = new byte[BUFFERSIZE];
            fixed(byte *pb = TempBuf)
            {
                *(TDefaultMessage *)(pb) = sMsg;
            }

            int DestLen = Encode6BitBuf(TempBuf, EncBuf, Marshal.SizeOf(typeof(TDefaultMessage)), BUFFERSIZE);

            fixed(byte *pb = EncBuf)
            {
                result = HUtil32.SBytePtrToString((sbyte *)pb, 0, DestLen);
            }

            return(result);
        }
Beispiel #6
0
        /// <summary>
        /// 加密Byte数组
        /// </summary>
        /// <param name="Buf"></param>
        /// <param name="bufsize"></param>
        /// <returns></returns>
        public unsafe static string EncodeBuffer(byte[] Buf, int bufsize)
        {
            string result;

            byte[] EncBuf  = new byte[BUFFERSIZE];
            byte[] TempBuf = new byte[BUFFERSIZE];
            if (bufsize < BUFFERSIZE)
            {
                Array.Copy(Buf, 0, TempBuf, 0, bufsize);
                int DestLen = Encode6BitBuf(TempBuf, EncBuf, bufsize, BUFFERSIZE);
                fixed(byte *pb = EncBuf)
                {
                    result = HUtil32.SBytePtrToString((sbyte *)pb, 0, DestLen);
                }
            }
            else
            {
                result = "";
            }
            return(result);
        }
Beispiel #7
0
        /// <summary>
        /// 解密字符串
        /// </summary>
        /// <param name="str">密文</param>
        /// <param name="chinese">是否返回中文</param>
        /// <returns></returns>
        public unsafe static string DeCodeString(string str, bool chinese = false)
        {
            string result;

            byte[] EncBuf = new byte[BUFFERSIZE];
            byte[] bSrc   = HUtil32.StringToByteAry(str);
            int    nLen   = Decode6BitBuf(bSrc, EncBuf, bSrc.Length, BUFFERSIZE);

            fixed(byte *pb = EncBuf)
            {
                if (chinese)
                {
                    result = HUtil32.SBytePtrToString((sbyte *)pb, nLen);
                }
                else
                {
                    result = HUtil32.SBytePtrToString((sbyte *)pb, 0, nLen);
                }
            }

            return(result);
        }
Beispiel #8
0
        /// <summary>
        /// 加密实体对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="Buf"></param>
        /// <returns></returns>
        public unsafe static string EncodeBuffer <T>(T Buf)
        {
            string result;

            byte[] EncBuf  = new byte[BUFFERSIZE];
            byte[] TempBuf = new byte[BUFFERSIZE];
            int    bufsize = Marshal.SizeOf(Buf);

            byte[] data = HUtil32.StructToBytes(Buf);
            if (bufsize < BUFFERSIZE)
            {
                Array.Copy(data, 0, TempBuf, 0, bufsize);
                int DestLen = Encode6BitBuf(TempBuf, EncBuf, bufsize, EncBuf.Length);
                fixed(byte *pb = EncBuf)
                {
                    result = HUtil32.SBytePtrToString((sbyte *)pb, 0, DestLen);
                }
            }
            else
            {
                result = "";
            }
            return(result);
        }