public async Task CompareFiles(string a, string b) { using var af = new FileStream(a, FileMode.Open); using var bf = new FileStream(b, FileMode.Open); Assert.Equal(af.Length, bf.Length); using var sha = new SHA256Managed(); var ha = BitConverter.ToString(await sha.ComputeHashAsync(af)); var hb = BitConverter.ToString(await sha.ComputeHashAsync(bf)); Assert.True(ha == hb); }
public static async Task HashPipe() { byte[] data = { 1, 2, 3, 5, 8, 13 }; using var alg = new SHA256Managed(); var hash = new byte[alg.HashSize / 8]; var pipe = new Pipe(); await pipe.Writer.WriteAsync(data); await alg.ComputeHashAsync(pipe.Reader, data.Length, hash); alg.Initialize(); Equal(hash, alg.ComputeHash(data)); }
public static async Task HashEntirePipe() { byte[] data = { 1, 2, 3, 5, 8, 13 }; using var alg = new SHA256Managed(); var hash = new byte[alg.HashSize / 8]; var pipe = new Pipe(); ThreadPool.QueueUserWorkItem(async state => { await pipe.Writer.WriteAsync(data); pipe.Writer.Complete(); }); await alg.ComputeHashAsync(pipe.Reader, hash); alg.Initialize(); Equal(hash, alg.ComputeHash(data)); }