Advertisement
gunnim

Untitled

Sep 8th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.75 KB | None | 0 0
  1.         public static string PathAndChecksum(string filePath)
  2.         {
  3.             return $"{filePath}?v={AppendFileChecksum(filePath)}";
  4.         }
  5.  
  6.         static string AppendFileChecksum(string filePath)
  7.         {
  8.             return _appCtx.ApplicationCache.RuntimeCache.GetCacheItem(filePath, () =>
  9.             {
  10.                 var fullFilePath = _httpCtx.Server.MapPath(filePath);
  11.  
  12.                 var fileStream = File.OpenRead(fullFilePath);
  13.  
  14.                 return CryptoHelpers.GetSHASum(fileStream);
  15.  
  16.             }).ToString();
  17.         }
  18.  
  19.         /// <summary>
  20.         /// SHA 256 sum of input stream
  21.         /// </summary>
  22.         public static string GetSHASum(Stream input)
  23.         {
  24.             var hasher = new SHA256Managed();
  25.             byte[] result = hasher.ComputeHash(input);
  26.  
  27.             string checkhash = BitConverter.ToString(result).Replace("-", "");
  28.  
  29.             return checkhash;
  30.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement