using System.Security.Cryptography; using System.Text.Unicode; namespace ConsoleApp4 { internal class Program { static void Main(string[] args) { string filePath = @"C:\Users\fred\Downloads\dotnet-sdk-9.0.100-win-x64.exe"; string sha512Str= RetrieveFileSHA512(filePath); Console.WriteLine($"File:{filePath}\nSHA512:{sha512Str}"); } static string RetrieveFileSHA512(string filePath) { string sha512Str = string.Empty; if (!File.Exists(filePath)) { return null; } using(FileStream fs=new FileStream(filePath,FileMode.Open,FileAccess.Read)) { using(SHA512 sha512=SHA512.Create()) { var shaBytes = sha512.ComputeHash(fs); if(shaBytes!=null && shaBytes.Any()) { sha512Str = BitConverter.ToString(shaBytes).Replace("-", "").ToLowerInvariant(); } } } return sha512Str; } } }
标签:retrieve,string,filePath,C#,CheckSum,shaBytes,sha512Str,using,sha512 From: https://www.cnblogs.com/Fred1987/p/18549695