Esempio n. 1
0
        public static ArrayList HashCrumbsInChunk(byte[] chunk)
        {
            //hash the crumbs
            uint nCrumbs = (uint)chunk.Length / Protocol.CrumbSize + 1;

            byte[]    crumbBuffer = new byte[Protocol.CrumbSize];
            byte[]    shortHashResult;
            byte[]    hashResult;
            uint      start         = 0;
            uint      end           = 0;
            MD4       md4           = new MD4();
            ArrayList crumbsHashSet = new ArrayList();

            while (end < chunk.Length - 1)
            {
                end = start + Protocol.CrumbSize - 1;
                if (end >= chunk.Length)
                {
                    end         = (uint)chunk.Length - 1;
                    crumbBuffer = new byte[end - start + 1];
                }
                Buffer.BlockCopy(chunk, (int)start, crumbBuffer, 0, (int)(end - start + 1));
                hashResult      = md4.GetByteHashFromBytes(crumbBuffer);
                shortHashResult = new byte[8];
                Buffer.BlockCopy(hashResult, 0, shortHashResult, 0, 8);
                crumbsHashSet.Add(shortHashResult);
                start = end + 1;
            }
            return(crumbsHashSet);
        }
Esempio n. 2
0
        /// <summary>
        /// A method for getting a ED2K hash from a specified file path
        /// </summary>
        /// <param name="filePath">The path for the file to hash</param>
        /// <returns>A string containing the ED2K hash</returns>
        public static string GetED2K(string filePath)
        {
            string hash = String.Empty;

            using (FileStream file = File.OpenRead(filePath))
            {
                byte[]      buffer;
                const int   CHUNK_SIZE      = 9728000;
                double      totalChunkCount = 0;
                long        chunkCount      = 0;
                int         bufferLength    = 0;
                MD4         md4             = new MD4();
                List <byte> md4HashedBytes  = new List <byte>();

                buffer          = new byte[CHUNK_SIZE];
                totalChunkCount = Math.Ceiling(file.Length * 1.0 / CHUNK_SIZE);
                while ((bufferLength = file.Read(buffer, 0, CHUNK_SIZE)) > 0)
                {
                    ++chunkCount;
                    byte[] chunkMd4HashedBytes = MD4.GetByteHashFromBytes(buffer.Take(bufferLength).ToArray());
                    md4HashedBytes.AddRange(chunkMd4HashedBytes);
                    buffer = new byte[CHUNK_SIZE];
                }

                hash = (chunkCount > 1
                        ? MD4.GetHexHashFromBytes(md4HashedBytes.ToArray())
                        : MD4.BytesToHex(md4HashedBytes.ToArray(), md4HashedBytes.Count)).ToLower();
            }

            return(hash);
        }
Esempio n. 3
0
        public static byte[] HashChunk(byte[] chunk)
        {
            byte[] resultHash;
            MD4    md4 = new MD4();

            resultHash = md4.GetByteHashFromBytes(chunk);
            return(resultHash);
        }
Esempio n. 4
0
        public static byte[] DoHashSetHash(ArrayList in_HashSet)
        {
            if (in_HashSet.Count == 0)
            {
                return(null);
            }
            byte[] unitedHash = new byte[16 * in_HashSet.Count];
            int    i          = 0;

            foreach (byte[] parcialHash in in_HashSet)
            {
                //				Array.Copy(HashParcial,0,HashUnido,16*i,16);
                Buffer.BlockCopy(parcialHash, 0, unitedHash, 16 * i, 16);
                i++;
            }
            byte[] resultHash = new byte[16];
            MD4    md4        = new MD4();

            resultHash = md4.GetByteHashFromBytes(unitedHash);
            return(resultHash);
        }
Esempio n. 5
0
        /// <summary>
        /// A method for getting a ED2K hash from a specified file path
        /// </summary>
        /// <param name="file">The FileStream to hash</param>
        /// <returns>A string containing the ED2K hash</returns>
        public static string GetED2K(FileStream file)
        {
            byte[]      buffer;
            const int   CHUNK_SIZE     = 9728000;
            long        chunkCount     = 0;
            List <byte> md4HashedBytes = new List <byte>();

            buffer = new byte[CHUNK_SIZE];
            int bufferLength;

            while ((bufferLength = file.Read(buffer, 0, CHUNK_SIZE)) > 0)
            {
                ++chunkCount;
                byte[] chunkMd4HashedBytes = MD4.GetByteHashFromBytes(buffer.Take(bufferLength).ToArray());
                md4HashedBytes.AddRange(chunkMd4HashedBytes);
                buffer = new byte[CHUNK_SIZE];
            }

            string hash = (chunkCount > 1
        ? MD4.GetHexHashFromBytes(md4HashedBytes.ToArray())
        : MD4.BytesToHex(md4HashedBytes.ToArray(), md4HashedBytes.Count)).ToLower();

            return(hash);
        }
Esempio n. 6
0
 public static byte[] DoHashSetHash(ArrayList in_HashSet)
 {
     if (in_HashSet.Count==0) return null;
     byte[] unitedHash=new byte[16*in_HashSet.Count];
     int i=0;
     foreach (byte[] parcialHash in in_HashSet)
     {
     //              Array.Copy(HashParcial,0,HashUnido,16*i,16);
     Buffer.BlockCopy(parcialHash,0,unitedHash,16*i,16);
     i++;
     }
     byte[] resultHash=new byte[16];
     MD4 md4=new MD4();
     resultHash=md4.GetByteHashFromBytes(unitedHash);
     return resultHash;
 }
Esempio n. 7
0
 public static byte[] HashChunk(byte[] chunk)
 {
     byte[] resultHash;
     MD4 md4=new MD4();
     resultHash=md4.GetByteHashFromBytes(chunk);
     return resultHash;
 }