feat(core): define primary models and services for encryption

This commit is contained in:
Stevan Freeborn
2026-02-06 06:44:54 -06:00
parent 6fdbe146c9
commit daab5ae8e7
5 changed files with 63 additions and 2 deletions
@@ -0,0 +1,21 @@
namespace FiscalOS.Core.Security;
public sealed record EncryptedDataKey
{
public string KeyIdUsed { get; init; }
public string EncryptedKey { get; init; }
private EncryptedDataKey(string keyIdUsed, string encryptedKey)
{
KeyIdUsed = keyIdUsed;
EncryptedKey = encryptedKey;
}
public static EncryptedDataKey From(string keyIdUsed, string encryptedKey)
{
ArgumentNullException.ThrowIfNull(keyIdUsed);
ArgumentNullException.ThrowIfNull(encryptedKey);
return new(keyIdUsed, encryptedKey);
}
}
+11
View File
@@ -0,0 +1,11 @@
namespace FiscalOS.Core.Security;
public interface IEncryptor
{
string GenerateKey();
Task<EncryptedDataKey> GenerateEncryptedKeyAsync(CancellationToken ct);
Task<string> EncryptAsync(string plainText, CancellationToken ct);
Task<string> EncryptAsyncFor(User user, string plainText, CancellationToken ct);
Task<string> DecryptAsync(string cipherText, CancellationToken ct);
Task<string> DecryptAsyncFor(User user, string plainText, CancellationToken ct);
}
+8
View File
@@ -0,0 +1,8 @@
namespace FiscalOS.Core.Security;
public interface IKeyRing
{
KeyRingEntry GetKey(string keyId);
KeyRingEntry GetPrimaryKey();
Task<KeyRingEntry> SaveKeyAsync(string key);
}
@@ -0,0 +1,21 @@
namespace FiscalOS.Core.Security;
public sealed record KeyRingEntry
{
public string KeyId { get; init; }
public string Key { get; init; }
private KeyRingEntry(string keyId, string key)
{
KeyId = keyId;
Key = key;
}
public static KeyRingEntry From(string keyId, string key)
{
ArgumentNullException.ThrowIfNull(keyId);
ArgumentNullException.ThrowIfNull(key);
return new(keyId, key);
}
}
+2 -2
View File
@@ -1,3 +1,3 @@
global using FiscalOS.Core.Data;
global using FiscalOS.Core.Identity;
global using FiscalOS.Core.Identity;
global using FiscalOS.Core.Security;