Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static string PathAndChecksum(string filePath)
- {
- return $"{filePath}?v={AppendFileChecksum(filePath)}";
- }
- static string AppendFileChecksum(string filePath)
- {
- return _appCtx.ApplicationCache.RuntimeCache.GetCacheItem(filePath, () =>
- {
- var fullFilePath = _httpCtx.Server.MapPath(filePath);
- var fileStream = File.OpenRead(fullFilePath);
- return CryptoHelpers.GetSHASum(fileStream);
- }).ToString();
- }
- /// <summary>
- /// SHA 256 sum of input stream
- /// </summary>
- public static string GetSHASum(Stream input)
- {
- var hasher = new SHA256Managed();
- byte[] result = hasher.ComputeHash(input);
- string checkhash = BitConverter.ToString(result).Replace("-", "");
- return checkhash;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement