rektor(RSA): Umbenennung von dir in cryptographer und Verschiebung der zugehörigen Klassen

This commit is contained in:
Developer 02 2024-12-05 10:03:39 +01:00
parent 6e4942c885
commit c38f7dcf72
7 changed files with 15 additions and 17 deletions

View File

@ -1,5 +1,6 @@
using DigitalData.Core.Abstractions.Security;
using DigitalData.Core.Security.Config;
using DigitalData.Core.Security.Cryptographer;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

View File

@ -1,7 +1,7 @@
using DigitalData.Core.Abstractions.Security;
using System.Security.Cryptography;
namespace DigitalData.Core.Security
namespace DigitalData.Core.Security.Cryptographer
{
public class RSACryptographer : IRSACryptographer
{
@ -14,7 +14,7 @@ namespace DigitalData.Core.Security
public string? Issuer { get; init; }
public string? Audience { get; init; }
internal RSACryptographer() { }
}
}

View File

@ -2,7 +2,7 @@
using DigitalData.Core.Security.Extensions;
using System.Security.Cryptography;
namespace DigitalData.Core.Security
namespace DigitalData.Core.Security.Cryptographer
{
public class RSADecryptor : RSACryptographer, IRSADecryptor, IRSACryptographer
{
@ -31,7 +31,7 @@ namespace DigitalData.Core.Security
protected override RSA RSA => lazyRSA.Value;
public RSADecryptor()
public RSADecryptor()
{
_lazyEncryptor = new(() => new RSAEncryptor()
{
@ -50,7 +50,7 @@ namespace DigitalData.Core.Security
return rsa;
});
}
public byte[] Decrypt(byte[] data) => RSA.Decrypt(data, Padding);
public string Decrypt(string data) => RSA.Decrypt(data.Base64ToByte(), Padding).BytesToString();

View File

@ -1,13 +1,13 @@
using DigitalData.Core.Abstractions.Security;
using DigitalData.Core.Security.Extensions;
namespace DigitalData.Core.Security
namespace DigitalData.Core.Security.Cryptographer
{
public class RSAEncryptor : RSACryptographer, IRSAEncryptor, IRSACryptographer
{
public override required string Pem
{
get => base.Pem;
{
get => base.Pem;
init
{
RSA.ImportFromPem(base.Pem);

View File

@ -3,7 +3,7 @@ using DigitalData.Core.Security.Config;
using Microsoft.Extensions.Options;
using System.Security.Cryptography;
namespace DigitalData.Core.Security
namespace DigitalData.Core.Security.Cryptographer
{
public class RSAFactory<TRSAFactoryParams> : IRSAFactory<TRSAFactoryParams> where TRSAFactoryParams : RSAFactoryParams
{
@ -12,7 +12,7 @@ namespace DigitalData.Core.Security
public static RSAFactory<RSAFactoryParams> Static => LazyInstance.Value;
protected readonly TRSAFactoryParams _params;
public RSAFactory(IOptions<TRSAFactoryParams> options) => _params = options.Value;
public string CreateRSAPrivateKeyPem(int? keySizeInBits = null)
@ -27,13 +27,13 @@ namespace DigitalData.Core.Security
{
password ??= _params.PbePassword;
var pbeParameters = (pbeEncryptionAlgorithm is null && hashAlgorithmName is null && iterationCount is null)
var pbeParameters = pbeEncryptionAlgorithm is null && hashAlgorithmName is null && iterationCount is null
? new PbeParameters(
pbeEncryptionAlgorithm ?? _params.PbeEncryptionAlgorithm,
hashAlgorithmName ?? _params.PbeHashAlgorithmName,
iterationCount ?? _params.PbeIterationCount)
: _params.PbeParameters;
var encryptedPrivateKey = RSA.Create(keySizeInBits ?? _params.KeySizeInBits).ExportEncryptedPkcs8PrivateKey(password.AsSpan(), pbeParameters);
var pemChars = PemEncoding.Write(_params.EncryptedPrivateKeyPemLabel, encryptedPrivateKey);
@ -47,7 +47,7 @@ namespace DigitalData.Core.Security
(string Value, Version Version)? versionedPassword = null;
if(version is not null)
if (version is not null)
{
if (version != Secrets.Version)
throw new InvalidOperationException($"The provided version {version} does not match the expected version {Secrets.Version}.");

View File

@ -1,5 +1,6 @@
using DigitalData.Core.Abstractions.Security;
using DigitalData.Core.Security.Config;
using DigitalData.Core.Security.Cryptographer;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;

View File

@ -15,8 +15,4 @@
<ProjectReference Include="..\DigitalData.Core.Security.Extensions\DigitalData.Core.Security.Extensions.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="RSA\" />
</ItemGroup>
</Project>