public bool VerifyUpdate(string filePath, Stream sha512sumFile, string originalFileName) { using (var hashAlgorithm = new SHA512Managed()) using (var file = this.filesystemProvider.OpenRead(filePath)) { try { return(ChecksumFileUtilities.ValidateChecksum(hashAlgorithm, sha512sumFile, originalFileName, file)); } catch (ArgumentException) { logger.Warn("Could not find checksum for file {0}", originalFileName); return(false); } } }
private static void Verify(string[] args) { if (args.Length < 5) { ShowHelp(); return; } var checksumFileName = args[1]; var algorithmName = args[2]; var certificateFileName = args[3]; var inputFileNames = args.Skip(4).ToArray(); // Signature first, then hash using (var checksumFile = File.OpenRead(checksumFileName)) using (var certificate = File.OpenRead(certificateFileName)) { Stream cleartext; var passed = PgpClearsignUtilities.ReadAndVerifyFile(checksumFile, certificate, out cleartext); using (cleartext) { if (!passed) { throw new Exception("Signature verification failed"); } using (var hashAlgorithm = HashAlgorithm.Create(algorithmName)) { foreach (var inputFileName in inputFileNames) { using (var inputFile = File.OpenRead(inputFileName)) { var valid = ChecksumFileUtilities.ValidateChecksum(hashAlgorithm, cleartext, Path.GetFileName(inputFileName), inputFile); if (!valid) { throw new Exception($"File {inputFileName} failed checksum"); } } } } } } Console.WriteLine("All files successfully verified"); }