public bool VerifySha512sum(string filePath, out Stream cleartext)
 {
     using (var file = this.filesystemProvider.OpenRead(filePath))
         using (var certificate = this.LoadCertificate())
         {
             return(PgpClearsignUtilities.ReadAndVerifyFile(file, certificate, out cleartext));
         }
 }
Exemple #2
0
        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");
        }