Ejemplo n.º 1
0
 public HashHelper(EHashType type, Encoding codec, string cad)
 {
     if (codec != null && !string.IsNullOrEmpty(cad))
     {
         byte[] raw = codec.GetBytes(cad);
         _Raw = HashRaw(type, raw, 0, raw.Length);
         _Hex = HexHelper.Buffer2Hex(_Raw);
     }
 }
Ejemplo n.º 2
0
        public static string HashHex(EHashType type, Encoding codec, string cad)
        {
            if (string.IsNullOrEmpty(cad))
            {
                return(null);
            }

            byte[] raw = codec.GetBytes(cad);
            raw = HashRaw(type, raw, 0, raw.Length);
            return(HexHelper.Buffer2Hex(raw));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Object to string
        /// </summary>
        /// <param name="value">Value</param>
        public static string ToString(object value)
        {
            if (value == null)
            {
                return("NULL");
            }

            if (value is IList)
            {
                IList l = (IList)value;
                Type  t = l.GetType();
                if (t.IsArray && value is byte[])
                {
                    t = t.GetElementType();
                    if (!t.IsEnum)
                    {
                        value = HexHelper.Buffer2Hex((byte[])l, ":");
                    }
                }
                return(string.Join(",", (l).OfType <object>().Select(u => u.ToString())));
            }
            else if (value is Array)
            {
                Array l = (Array)value;
                Type  t = l.GetType();
                if (t.IsArray && value is byte[])
                {
                    t = t.GetElementType();
                    if (!t.IsEnum)
                    {
                        value = HexHelper.Buffer2Hex((byte[])l, ":");
                    }
                }
                return(string.Join(",", (l).OfType <object>().Select(u => u.ToString())));
            }
            else if (value is Encoding)
            {
                Encoding l = (Encoding)value;
                return(l.BodyName);
            }

            return(value.ToString());
        }
Ejemplo n.º 4
0
 public static string HashHex(EHashType type, Stream bs, bool seekBegin)
 {
     return(HexHelper.Buffer2Hex(HashRaw(type, bs, seekBegin)));
 }
Ejemplo n.º 5
0
 public static string HashHex(EHashType type, byte[] bs, int index, int length)
 {
     return(HexHelper.Buffer2Hex(HashRaw(type, bs, index, length)));
 }
Ejemplo n.º 6
0
 public HashHelper(EHashType type, byte[] bx)
 {
     _Raw = HashRaw(type, bx, 0, bx.Length);
     _Hex = HexHelper.Buffer2Hex(_Raw);
 }