private string HashFile(System.IO.Stream stream, string strAlgName) { System.Security.Cryptography.HashAlgorithm algorithm; if (strAlgName == null) { logTrace.TraceWarning("algName 不能为空"); } if (string.Compare(strAlgName, "sha1", true) == 0) { algorithm = System.Security.Cryptography.SHA1.Create(); } else { if (string.Compare(strAlgName, "md5", true) != 0) { logTrace.TraceWarning("algName 只能使用 sha1 或 md5"); } algorithm = System.Security.Cryptography.MD5.Create(); } return(BitConverter.ToString(algorithm.ComputeHash(stream)).Replace("-", "")); }