using DigitalData.Core.Abstractions.Security.Key;
using DigitalData.Core.Security.RSAKey.Base;
using System.Reflection;
using System.Security.Cryptography;

namespace DigitalData.Core.Security.RSAKey.Crypto;

public class RSAEncryptor : RSAPublicKey, IAsymmetricEncryptor
{
    public RSAEncryptionPadding Padding { get; init; } = RSAEncryptionPadding.OaepSHA256;

    // TODO: add as json converter to IConfigurIConfiguration.Config
    public string PaddingName
    {
        get => Padding.ToString();
        init => Padding = typeof(RSAEncryptionPadding).GetProperty(value, BindingFlags.Public | BindingFlags.Static)?.GetValue(null) as RSAEncryptionPadding ?? throw new ArgumentException($"Padding '{value}' not found.");
    }

    public byte[] Encrypt(byte[] data) => RSA.Encrypt(data, Padding);
}