feat(RSAFactory.ReadRSADecryptorAsync): ReadRSADecryptorAsync-Methode hinzugefügt, um die pem-Datei zu lesen und den Decryptor asynchron zu erstellen
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
{
|
||||
public interface IRSADecryptor : IRSACryptographer
|
||||
{
|
||||
(string Value, Version Version) VersionedPassword { init; }
|
||||
(string Value, Version Version)? VersionedPassword { init; }
|
||||
|
||||
Version? PasswordVersion { get; }
|
||||
|
||||
|
||||
@@ -6,12 +6,12 @@ namespace DigitalData.Core.Security
|
||||
{
|
||||
public class RSADecryptor : RSACryptographer, IRSADecryptor, IRSACryptographer
|
||||
{
|
||||
public (string Value, Version Version) VersionedPassword
|
||||
public (string Value, Version Version)? VersionedPassword
|
||||
{
|
||||
init
|
||||
{
|
||||
_password = value.Value;
|
||||
PasswordVersion = value.Version;
|
||||
_password = value?.Value;
|
||||
PasswordVersion = value?.Version;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Security.Cryptography;
|
||||
using DigitalData.Core.Abstractions.Security;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace DigitalData.Core.Security
|
||||
@@ -106,5 +107,26 @@ namespace DigitalData.Core.Security
|
||||
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user