feat(RSAFactory.ReadRSADecryptorAsync): ReadRSADecryptorAsync-Methode hinzugefügt, um die pem-Datei zu lesen und den Decryptor asynchron zu erstellen

This commit is contained in:
Developer 02
2024-11-22 09:06:58 +01:00
parent f7193594b1
commit 70ccec9fef
3 changed files with 27 additions and 5 deletions

View File

@@ -2,7 +2,7 @@
{ {
public interface IRSADecryptor : IRSACryptographer public interface IRSADecryptor : IRSACryptographer
{ {
(string Value, Version Version) VersionedPassword { init; } (string Value, Version Version)? VersionedPassword { init; }
Version? PasswordVersion { get; } Version? PasswordVersion { get; }

View File

@@ -6,12 +6,12 @@ namespace DigitalData.Core.Security
{ {
public class RSADecryptor : RSACryptographer, IRSADecryptor, IRSACryptographer public class RSADecryptor : RSACryptographer, IRSADecryptor, IRSACryptographer
{ {
public (string Value, Version Version) VersionedPassword public (string Value, Version Version)? VersionedPassword
{ {
init init
{ {
_password = value.Value; _password = value?.Value;
PasswordVersion = value.Version; PasswordVersion = value?.Version;
} }
} }

View File

@@ -1,4 +1,5 @@
using System.Security.Cryptography; using DigitalData.Core.Abstractions.Security;
using System.Security.Cryptography;
using System.Text; using System.Text;
namespace DigitalData.Core.Security namespace DigitalData.Core.Security
@@ -106,5 +107,26 @@ namespace DigitalData.Core.Security
return new string(pemChars); return new string(pemChars);
} }
public async Task<IRSADecryptor> ReadRSADecryptorAsync(string path, Version? version = null, CancellationToken cancellationToken = default)
{
var pem = await File.ReadAllTextAsync(path, cancellationToken);
(string Value, Version Version)? versionedPassword = 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}.");
versionedPassword = (Secrets.PBE_PASSWORD, Secrets.Version);
}
return new RSADecryptor()
{
Pem = pem,
VersionedPassword = versionedPassword
};
}
} }
} }