예제 #1
0
파일: CRC32.cs 프로젝트: n3wt0n/Crypto
        /// <summary>
        /// Hash a file using CRC32
        /// </summary>
        /// <param name="sourceFile">The file to hash complete path</param>
        /// <returns>The hash</returns>
        public string HashFile(string sourceFile)
        {
            if (sourceFile.IsNullOrWhiteSpace() || !File.Exists(sourceFile))
                throw new FileNotFoundException("Cannot find the specified source file", sourceFile ?? "null");

            byte[] fileBytes = File.ReadAllBytes(sourceFile);
            using (var crc32 = new CRC32Impl())
            {
                return crc32.ComputeChecksumAsString(fileBytes);
            }
        }
예제 #2
0
파일: CRC32.cs 프로젝트: n3wt0n/Crypto
 /// <summary>
 /// Hash a string using CRC32
 /// </summary>
 /// <param name="sourceString">The string to hash</param>
 /// <returns>The hash</returns>
 public string HashString(string sourceString)
 {
     if (sourceString != null)
     {
         using (var crc32 = new CRC32Impl())
         {
             return crc32.ComputeChecksumAsString(sourceString.ToByteArray());
         }
     }
     else
         return String.Empty;
 }