示例#1
0
 public static string xxHash(this byte[] data, bool nullOnIOError = false)
 {
     try
     {
         var hash = new xxHashConfig();
         hash.HashSizeInBits = 64;
         hash.Seed           = 0x42;
         using (var fs = new MemoryStream(data))
         {
             var config = new xxHashConfig();
             config.HashSizeInBits = 64;
             using (var f = new StatusFileStream(fs, $"Hashing memory stream"))
             {
                 var value = xxHashFactory.Instance.Create(config).ComputeHash(f);
                 return(value.AsBase64String());
             }
         }
     }
     catch (IOException ex)
     {
         if (nullOnIOError)
         {
             return(null);
         }
         throw ex;
     }
 }
示例#2
0
 public static string FileHash(this string file, bool nullOnIOError = false)
 {
     try
     {
         var hash = new xxHashConfig();
         hash.HashSizeInBits = 64;
         hash.Seed           = 0x42;
         using (var fs = File.OpenRead(file))
         {
             var config = new xxHashConfig();
             config.HashSizeInBits = 64;
             using (var f = new StatusFileStream(fs, $"Hashing {Path.GetFileName(file)}"))
             {
                 var value = xxHashFactory.Instance.Create(config).ComputeHash(f);
                 return(value.AsBase64String());
             }
         }
     }
     catch (IOException ex)
     {
         if (nullOnIOError)
         {
             return(null);
         }
         throw ex;
     }
 }