feat(core): define primary models and services for encryption
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
global using FiscalOS.Core.Data;
|
||||
|
||||
global using FiscalOS.Core.Identity;
|
||||
global using FiscalOS.Core.Identity;
|
||||
global using FiscalOS.Core.Security;
|
||||
Reference in New Issue
Block a user