实用函数系列:文件SHA1值计算

        /// <summary>
        /// 计算文件大写40位SHA1值,用于文件唯一性校验
         /// </summary>
        /// <param name="fileName">文件名</param>
        /// <returns>文件大写SHA1值</returns>
        public static string FileSHA1Compute(string fileName)
        {
            using (FileStream fs = new FileStream(fileName, FileMode.Open))
            {
                SHA1CryptoServiceProvider sp = new SHA1CryptoServiceProvider();
                byte[] result = sp.ComputeHash(fs);
                StringBuilder sb = new StringBuilder();
                foreach (byte item in result)
                    sb.AppendFormat("{0:X2}", item);
                return sb.ToString();
            }
        }
posted @ 2010-11-29 15:52  zhangke0504  阅读(482)  评论(0编辑  收藏  举报