public byte[] ComputeHash(byte[] buffer, int offset, int count) { Initialize(); HashCore(buffer, offset, count); HashValue = HashFinal(); return((byte[])HashValue.Clone()); }
public new byte[] ComputeHash(Stream stream) { size = stream.Length; totalBytesRead = 0; isHashing = true; // Default the buffer size to 4K. byte[] buffer = new byte[4096]; int bytesRead; do { bytesRead = stream.Read(buffer, 0, 4096); if (bytesRead > 0) { HashCore(buffer, 0, bytesRead); } } while (bytesRead > 0 && isHashing); if (!isHashing) { Initialize(); return(null); } HashValue = HashFinal(); byte[] Tmp = (byte[])HashValue.Clone(); Initialize(); return(Tmp); }
/// <summary> /// </summary> /// <param name="Algo"></param> public byte[] ComputeLargeStreamHash(Stream Stream, RateTracker Tracker, ChecksumProgressEventHandler Callback) { // Buffer size optimized for reading massive files. byte[] buffer = MemoryPool.AllocBuffer(BufferSize); int bytesRead; do { bytesRead = Stream.Read(buffer, 0, BufferSize); if (bytesRead > 0) { HashCore(buffer, 0, bytesRead); if (Callback != null) { Callback?.Invoke(bytesRead); } if (Tracker != null) { Tracker.Out(bytesRead); } } } while (bytesRead > 0); HashValue = HashFinal(); byte[] Tmp = (byte[])HashValue.Clone(); Initialize(); MemoryPool.ReleaseBuffer(buffer); return(Tmp); }
private byte[] CaptureHashCodeAndReinitialize() { HashValue = HashFinal(); // Clone the hash value prior to invoking Initialize in case the user-defined Initialize // manipulates the array. byte[] tmp = (byte[])HashValue.Clone(); Initialize(); return(tmp); }
public byte[] ComputeHash(Stream inputStream) { Initialize(); int count; byte[] buffer = new byte[4096]; while (0 < (count = inputStream.Read(buffer, 0, 4096))) { HashCore(buffer, 0, count); } HashValue = HashFinal(); return((byte[])HashValue.Clone()); }