public static async Task <byte[]> WriteUserDataFileAsync(string sourcePath, string destinationPath, byte[] key, byte[] iv) { await using var src = new FileStream(sourcePath, FileMode.Open, FileAccess.Read); await using var dest = new FileStream(destinationPath, FileMode.Create, FileAccess.Write); using var encryptor = QuickAesTransform.CreateEncryptor(key, iv); await using var destCrypto = new CryptoStream(dest, encryptor, CryptoStreamMode.Write); var hash = await src.CopyToCreateHashAsync(destCrypto); return(hash); }
public async Task HashIsCorrect() { var timer = Stopwatch.StartNew(); await using var sourceStream = new FileStream(TestFile, FileMode.Open, FileAccess.Read); await using var outputStream = new FileStream("HashIsCorrect.td", FileMode.Create, FileAccess.Write); using var sha = SHA256.Create(); var hashFromCompute = sha.ComputeHash(sourceStream); sourceStream.Position = 0; var hashFromCopy = await sourceStream.CopyToCreateHashAsync(outputStream); Console.WriteLine(timer.ElapsedMilliseconds + "ms"); Assert.AreEqual(hashFromCompute, hashFromCopy); }