21 lines
562 B
C#
21 lines
562 B
C#
using System.Security.Cryptography;
|
|
using System.Text;
|
|
|
|
namespace line_gestao_api.Services;
|
|
|
|
public static class DeterministicGuid
|
|
{
|
|
public static Guid FromString(string input)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(input))
|
|
{
|
|
throw new ArgumentException("Valor obrigatório para gerar Guid determinístico.", nameof(input));
|
|
}
|
|
|
|
var hash = SHA256.HashData(Encoding.UTF8.GetBytes(input));
|
|
Span<byte> bytes = stackalloc byte[16];
|
|
hash.AsSpan(0, 16).CopyTo(bytes);
|
|
return new Guid(bytes);
|
|
}
|
|
}
|