forked from xiongyuxing/tiku-backend.net
feat: harden SaaS authentication and authorization
This commit is contained in:
@@ -6,10 +6,29 @@ namespace Tiku.Infrastructure.Auth;
|
||||
|
||||
public static class SmsCodeHashing
|
||||
{
|
||||
public static string Hash(Guid tenantId, string phone, SmsPurpose purpose, string code)
|
||||
public static string Hash(
|
||||
Guid tenantId,
|
||||
string phone,
|
||||
SmsPurpose purpose,
|
||||
string code,
|
||||
string pepper)
|
||||
{
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(pepper);
|
||||
|
||||
var normalized = $"{tenantId:N}:{NormalizePhone(phone)}:{purpose}:{code.Trim()}";
|
||||
var hash = SHA256.HashData(Encoding.UTF8.GetBytes(normalized));
|
||||
var hash = HMACSHA256.HashData(
|
||||
Encoding.UTF8.GetBytes(pepper),
|
||||
Encoding.UTF8.GetBytes(normalized));
|
||||
return Convert.ToHexString(hash).ToLowerInvariant();
|
||||
}
|
||||
|
||||
public static string HashScope(string value, string pepper)
|
||||
{
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(pepper);
|
||||
|
||||
var hash = HMACSHA256.HashData(
|
||||
Encoding.UTF8.GetBytes(pepper),
|
||||
Encoding.UTF8.GetBytes(value.Trim().ToLowerInvariant()));
|
||||
return Convert.ToHexString(hash).ToLowerInvariant();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user