private static bool VerifyFile(FileInfo file, string checksum) { using (SHA1CryptoServiceProvider crypto = new SHA1CryptoServiceProvider()) { var buffer = File.ReadAllBytes(file.FullName); var hash = ZsyncUtil.ByteToHex(crypto.ComputeHash(buffer)); return(hash == checksum); } }
public static void Make(FileInfo file) { //var blockSize = 2048; var fileLength = file.Length; var blockSize = CalculateBlocksize(file.Length); var sequenceMatches = fileLength > blockSize ? 2 : 1; var weakChecksumLength = CalculateWeakChecksumLength(fileLength, blockSize, sequenceMatches); var strongCheckSumLength = CalculateStrongChecksumLength(fileLength, blockSize, sequenceMatches); var checkSums = ComputeCheckSums(file, blockSize, fileLength, weakChecksumLength, strongCheckSumLength); var mtime = File.GetLastWriteTimeUtc(file.FullName); var header = new Header(ZsyncVersion, file.Name, mtime, blockSize, fileLength, sequenceMatches, weakChecksumLength, strongCheckSumLength, null, ZsyncUtil.ByteToHex(checkSums.sha1)); var zsyncFile = new FileInfo(file.FullName + ".zsync"); WriteFile(header, new MemoryStream(checkSums.checksums), zsyncFile); }