using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Security.Cryptography; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { HashAlgorithm hash = HashAlgorithm.Create(); Console.WriteLine("Enter a File Name:"); string fileName = Console.ReadLine(); FileStream fs = new FileStream(fileName, FileMode.Open); byte[] hashBytes = hash.ComputeHash(fs); fs.Close(); Console.Write("Hash:"+BitConverter.ToString(hashBytes)); Console.ReadLine(); } } } 注:该句HashAlgorithm hash=HashAlgorithm.Create();是实现是SHA1类的实例,生成的是160位的散列码。 如果将上句改为:HashAlgorithm hash=HashAlgorithm.Create("SHA256"); 则是生成256位的散列码。 或者:SHA256Managed has