[CHANGE] Working on auth hash

This commit is contained in:
max
2025-09-04 20:32:39 +02:00
parent 431a103fac
commit 92e5bb7f1f
6 changed files with 90 additions and 28 deletions

View File

@@ -10,16 +10,24 @@ public static class AuthenticationUtilities
private const string HeaderScheme = "SAPISIDHASH";
// Dave Thomas @ https://stackoverflow.com/a/32065323/9948300
public static AuthenticationHeaderValue? GetSapisidHashHeader(string sapisid, string origin)
public static AuthenticationHeaderValue? GetSapisidHashHeader(string datasyncId, string sapisid, string origin)
{
if (string.IsNullOrWhiteSpace(sapisid) || string.IsNullOrWhiteSpace(origin))
return null;
var time = GetTime();
var sha1 = HashString($"{time} {sapisid} {origin}");
var completeHash = $"{time}_{sha1}";
return new AuthenticationHeaderValue(HeaderScheme, completeHash);
var strHash = GetSapisidHash(datasyncId, sapisid, origin);
return new AuthenticationHeaderValue(HeaderScheme, strHash);
}
public static string? GetSapisidHash(string datasyncId, string sapisid, string origin)
{
if (string.IsNullOrWhiteSpace(datasyncId) || string.IsNullOrWhiteSpace(sapisid) || string.IsNullOrWhiteSpace(origin))
return null;
datasyncId = datasyncId.Replace("||", "");
sapisid = Uri.UnescapeDataString(sapisid);
var time = GetTime();
var sha1 = HashString($"{datasyncId} {time} {sapisid} {origin}");
var completeHash = $"{time}_{sha1}_u";
return completeHash;
}
private static string HashString(string stringData)
{
var dataBytes = Encoding.ASCII.GetBytes(stringData);