Replace MD5 hash with a longer simple hash

This commit is contained in:
David Montesinos
2025-04-21 15:51:25 +02:00
parent 1b00fa74bc
commit e7acd14faa
2 changed files with 11 additions and 5 deletions

View File

@ -144,7 +144,7 @@ namespace Oqtane.Pages
etagInput += $":{Request.QueryString.Value}"; etagInput += $":{Request.QueryString.Value}";
} }
etag = Utilities.GenerateHashMD5(etagInput); etag = Utilities.GenerateSimpleHash16(etagInput);
var header = ""; var header = "";
if (HttpContext.Request.Headers.TryGetValue(HeaderNames.IfNoneMatch, out var ifNoneMatch)) if (HttpContext.Request.Headers.TryGetValue(HeaderNames.IfNoneMatch, out var ifNoneMatch))

View File

@ -620,11 +620,17 @@ namespace Oqtane.Shared
} }
} }
public static string GenerateHashMD5(string input) public static string GenerateSimpleHash16(string text)
{ {
var bytes = Encoding.UTF8.GetBytes(input); unchecked // prevent overflow exception
var hashBytes = MD5.HashData(bytes); {
return Convert.ToHexString(hashBytes); long hash = 23;
foreach (char c in text)
{
hash = hash * 31 + c;
}
return hash.ToString("X16");
}
} }
[Obsolete("ContentUrl(Alias alias, int fileId) is deprecated. Use FileUrl(Alias alias, int fileId) instead.", false)] [Obsolete("ContentUrl(Alias alias, int fileId) is deprecated. Use FileUrl(Alias alias, int fileId) instead.", false)]