Esempio n. 1
0
        public static string HashHex(EHashType type, Encoding codec, string cad)
        {
            if (string.IsNullOrEmpty(cad)) return null;

            byte[] raw = HashRaw(type, codec.GetBytes(cad));
            return HexHelper.Buffer2Hex(raw);
        }
Esempio n. 2
0
 public HashHelper(EHashType type, Encoding codec, string cad)
 {
     if (codec != null && !string.IsNullOrEmpty(cad))
     {
         _Raw = HashRaw(type, codec.GetBytes(cad));
         _Hex = HexHelper.Buffer2Hex(_Raw);
     }
 }
Esempio n. 3
0
 public static string HashHexFile(EHashType type, string file)
 {
     try
     {
         using (FileStream fs = File.OpenRead(file))
             return HashHex(type, fs, false);
     }
     catch { }
     return null;
 }
Esempio n. 4
0
        public static byte[] HashRaw(EHashType type, byte[] bs)
        {
            if (bs == null) return null;

            HashAlgorithm cmd5 = null;
            switch (type)
            {
                case EHashType.Md5: cmd5 = new MD5CryptoServiceProvider(); break;
                case EHashType.Sha1: cmd5 = new SHA1CryptoServiceProvider(); break;
                case EHashType.Sha256: cmd5 = new SHA256CryptoServiceProvider(); break;
                case EHashType.Sha384: cmd5 = new SHA384CryptoServiceProvider(); break;
                case EHashType.Sha512: cmd5 = new SHA512CryptoServiceProvider(); break;
            }

            bs = cmd5.ComputeHash(bs);
            cmd5.Dispose();
            return bs;
        }
Esempio n. 5
0
        public static byte[] HashRaw(EHashType type, Stream bs, bool seekBegin)
        {
            if (bs == null) return null;

            HashAlgorithm cmd5 = null;
            switch (type)
            {
                case EHashType.Md5: cmd5 = new MD5CryptoServiceProvider(); break;
                case EHashType.Sha1: cmd5 = new SHA1CryptoServiceProvider(); break;
                case EHashType.Sha256: cmd5 = new SHA256CryptoServiceProvider(); break;
                case EHashType.Sha384: cmd5 = new SHA384CryptoServiceProvider(); break;
                case EHashType.Sha512: cmd5 = new SHA512CryptoServiceProvider(); break;
            }

            if (seekBegin) bs.Seek(0, SeekOrigin.Begin);

            byte[] bsh = cmd5.ComputeHash(bs);
            cmd5.Dispose();
            return bsh;
        }
Esempio n. 6
0
 public static string HashHex(EHashType type, string cad)
 {
     return(HashHex(type, Encoding.UTF8, cad));
 }
Esempio n. 7
0
 public HashHelper(EHashType type, byte[] bx)
 {
     _Raw = HashRaw(type, bx, 0, bx.Length);
     _Hex = HexHelper.Buffer2Hex(_Raw);
 }
Esempio n. 8
0
 public HashHelper(EHashType type, string cad) : this(type, Encoding.UTF8, cad)
 {
 }
Esempio n. 9
0
 public static string HashHex(EHashType type, Stream bs, bool seekBegin)
 {
     return(HexHelper.Buffer2Hex(HashRaw(type, bs, seekBegin)));
 }
Esempio n. 10
0
 public static string HashHex(EHashType type, byte[] bs, int index, int length)
 {
     return(HexHelper.Buffer2Hex(HashRaw(type, bs, index, length)));
 }
Esempio n. 11
0
 public static string HashHex(EHashType type, Stream bs, bool seekBegin) { return HexHelper.Buffer2Hex(HashRaw(type, bs, seekBegin)); }
Esempio n. 12
0
 public static string HashHex(EHashType type, byte[] bs) { return HexHelper.Buffer2Hex(HashRaw(type, bs)); }
Esempio n. 13
0
 public static string HashHex(EHashType type, string cad) { return HashHex(type, Encoding.UTF8, cad); }
Esempio n. 14
0
 public HashHelper(EHashType type, byte[] bx)
 {
     _Raw = HashRaw(type, bx);
     _Hex = HexHelper.Buffer2Hex(_Raw);
 }
Esempio n. 15
0
 public HashHelper(EHashType type, string cad) : this(type, Encoding.UTF8, cad) { }
 public LibraHasher(EHashType eHashType)
 {
     _eHashType = eHashType;
 }