feat(RSAFactoryParams): Umbenennung von PbeHashAlgorithmName in PbeHashAlgorithm und Hinzufügen von String-Proportionen mit dem Namen von PbeHashAlgorithmName.
- PbeHashAlgorithmName.init Methoden hinzugefügt, um zu versuchen, PbeHashAlgorithm mit Reflection zu initialisieren. Wenn er null ist, wird er nach dem Namen generiert. - PbeHashAlgorithmName.get hinzugefügt, um den Namen von PbeHashAlgorithm zu erhalten.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Reflection;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace DigitalData.Core.Security.Config
|
||||
@@ -11,7 +12,16 @@ namespace DigitalData.Core.Security.Config
|
||||
|
||||
public PbeEncryptionAlgorithm PbeEncryptionAlgorithm { get; init; } = PbeEncryptionAlgorithm.Aes256Cbc;
|
||||
|
||||
public HashAlgorithmName PbeHashAlgorithmName { get; init; } = HashAlgorithmName.SHA256;
|
||||
public HashAlgorithmName PbeHashAlgorithm { get; init; } = HashAlgorithmName.SHA256;
|
||||
|
||||
// TODO: add as json converter to IConfigurIConfiguration.Config
|
||||
public string PbeHashAlgorithmName
|
||||
{
|
||||
get => PbeHashAlgorithm.ToString();
|
||||
init => PbeHashAlgorithm = (typeof(HashAlgorithmName).GetProperty(value, BindingFlags.Public | BindingFlags.Static)?.GetValue(null) is HashAlgorithmName hashAlgorithmName)
|
||||
? hashAlgorithmName
|
||||
: new(value);
|
||||
}
|
||||
|
||||
public int PbeIterationCount { get; init; } = 100_000;
|
||||
|
||||
@@ -37,7 +47,7 @@ namespace DigitalData.Core.Security.Config
|
||||
return true;
|
||||
});
|
||||
|
||||
AfterCreate += () => _pbeParameters = new PbeParameters(PbeEncryptionAlgorithm, PbeHashAlgorithmName, PbeIterationCount);
|
||||
AfterCreate += () => _pbeParameters = new PbeParameters(PbeEncryptionAlgorithm, PbeHashAlgorithm, PbeIterationCount);
|
||||
}
|
||||
|
||||
protected event Action AfterCreate;
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace DigitalData.Core.Security.Cryptographer
|
||||
var pbeParameters = pbeEncryptionAlgorithm is null && hashAlgorithmName is null && iterationCount is null
|
||||
? new PbeParameters(
|
||||
pbeEncryptionAlgorithm ?? _params.PbeEncryptionAlgorithm,
|
||||
hashAlgorithmName ?? _params.PbeHashAlgorithmName,
|
||||
hashAlgorithmName ?? _params.PbeHashAlgorithm,
|
||||
iterationCount ?? _params.PbeIterationCount)
|
||||
: _params.PbeParameters;
|
||||
|
||||
|
||||
@@ -13,9 +13,6 @@ namespace DigitalData.Core.Security
|
||||
{
|
||||
public static JsonSerializerOptions AddCryptographerConverter(this JsonSerializerOptions options)
|
||||
{
|
||||
if (!options.Converters.OfType<HashAlgorithmNameConverter>().Any())
|
||||
options.Converters.Add(new HashAlgorithmNameConverter());
|
||||
|
||||
if (!options.Converters.OfType<JsonStringEnumConverter>().Any())
|
||||
options.Converters.Add(new JsonStringEnumConverter());
|
||||
return options;
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace DigitalData.Core.Security
|
||||
{
|
||||
public class HashAlgorithmNameConverter : JsonConverter<HashAlgorithmName>
|
||||
{
|
||||
public override HashAlgorithmName Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => new(reader.GetString() ?? string.Empty);
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, HashAlgorithmName value, JsonSerializerOptions options) => writer.WriteStringValue(value.Name);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user