Files
stevanfreeborn.secureconfig/src/StevanFreeborn.Extensions.Configuration.Secure/Cryptography/MachineIdKeyProvider.cs
T

21 lines
575 B
C#
Raw Normal View History

2026-03-31 07:15:03 -05:00
using System.Security.Cryptography;
using System.Text;
namespace StevanFreeborn.Extensions.Configuration.Secure.Cryptography;
2026-03-31 07:15:03 -05:00
internal sealed class MachineIdKeyProvider(IMachineIdKeyGenerator generator) : IEncryptionKeyProvider
{
2026-03-31 07:15:03 -05:00
private readonly IMachineIdKeyGenerator _generator = generator;
public byte[] GetKey()
{
var machineId = _generator.GetId();
var @bytes = Encoding.UTF8.GetBytes(machineId);
2026-04-02 13:50:47 -05:00
#if NET5_0_OR_GREATER
return SHA256.HashData(@bytes);
#else
2026-03-31 07:15:03 -05:00
using var sha256 = SHA256.Create();
return sha256.ComputeHash(@bytes);
2026-04-02 13:50:47 -05:00
#endif
2026-03-31 07:15:03 -05:00
}
}