Get Sha256 with a buffered stream, THAT WILL NOT BE CLOSED! - CSharp System.IO

CSharp examples for System.IO:Stream

Description

Get Sha256 with a buffered stream, THAT WILL NOT BE CLOSED!

Demo Code


using System.Security.Cryptography;
using System.IO;/*from www .  j ava 2s  . c  om*/
using System;

public class Main{
        /// <summary>
        /// Get Sha256 with a buffered stream, THAT WILL NOT BE CLOSED!
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        public static string GetSha256HashBuffered(Stream stream)
        {
            var bufferedStream = new BufferedStream(stream, 1024*32); //todo check if this is the best buffersize
            
            var sha = new SHA256Managed();
            byte[] checksum = sha.ComputeHash(bufferedStream);
            return BitConverter.ToString(checksum).Replace("-", String.Empty);            
        }
}

Related Tutorials