EncryptionService should be using ISecretProvider
Remove Async from method that was not Async
This commit is contained in:
parent
ccb06b260c
commit
3e5ce9d81d
6 changed files with 44 additions and 31 deletions
|
|
@ -2,5 +2,5 @@ namespace IdentityShroud.Core.Contracts;
|
|||
|
||||
public interface ISecretProvider
|
||||
{
|
||||
string GetSecretAsync(string name);
|
||||
string GetSecret(string name);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ public class ConfigurationSecretProvider(IConfiguration configuration) : ISecret
|
|||
{
|
||||
private readonly IConfigurationSection secrets = configuration.GetSection("secrets");
|
||||
|
||||
public string GetSecretAsync(string name)
|
||||
public string GetSecret(string name)
|
||||
{
|
||||
return secrets.GetValue<string>(name) ?? "";
|
||||
}
|
||||
|
|
|
|||
36
IdentityShroud.Core/Services/EncryptionService.cs
Normal file
36
IdentityShroud.Core/Services/EncryptionService.cs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
using IdentityShroud.Core.Contracts;
|
||||
using IdentityShroud.Core.Security;
|
||||
|
||||
namespace IdentityShroud.Core.Services;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class EncryptionService : IEncryptionService
|
||||
{
|
||||
private readonly byte[] encryptionKey;
|
||||
|
||||
/// <summary>
|
||||
/// For easier usage in
|
||||
/// </summary>
|
||||
/// <param name="encryptionKey">Encryption key as base64, must be 32 bytes</param>
|
||||
// public EncryptionService(string keyBase64)
|
||||
// {
|
||||
// encryptionKey = Convert.FromBase64String(keyBase64);
|
||||
// }
|
||||
|
||||
public EncryptionService(ISecretProvider secretProvider)
|
||||
{
|
||||
encryptionKey = Convert.FromBase64String(secretProvider.GetSecret("Master"));
|
||||
}
|
||||
|
||||
public byte[] Encrypt(byte[] plain)
|
||||
{
|
||||
return AesGcmHelper.EncryptAesGcm(plain, encryptionKey);
|
||||
}
|
||||
|
||||
public byte[] Decrypt(byte[] cipher)
|
||||
{
|
||||
return AesGcmHelper.DecryptAesGcm(cipher, encryptionKey);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
using IdentityShroud.Core.Contracts;
|
||||
using IdentityShroud.Core.Security;
|
||||
|
||||
namespace IdentityShroud.Core.Services;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="encryptionKey">Encryption key as base64, must be 32 bytes</param>
|
||||
public class EncryptionService(string keyBase64) : IEncryptionService
|
||||
{
|
||||
private readonly byte[] encryptionKey = Convert.FromBase64String(keyBase64);
|
||||
|
||||
public byte[] Encrypt(byte[] plain)
|
||||
{
|
||||
return AesGcmHelper.EncryptAesGcm(plain, encryptionKey);
|
||||
}
|
||||
|
||||
public byte[] Decrypt(byte[] cipher)
|
||||
{
|
||||
return AesGcmHelper.DecryptAesGcm(cipher, encryptionKey);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue