AltairCA / EntityFrameworkCore.PostgreSQL.ColumnEncryption

NPGSQL Extension that supports native PostgreSql's [Raw Encryption Functions (encrypt_iv,decrypt_iv with aes-cbc/pad:pkcs)]
15 stars 3 forks source link

Suggestion for support of fluent configuration #7

Closed davidkeaveny closed 1 year ago

davidkeaveny commented 1 year ago

Would it be possible to add support for encrypting columns via extension methods on the PropertyBuilder<T> so that I can add encryption support to my model via the IEntityTypeConfiguration<T> interface rather than having to decorate my model with additional attributes?

e.g.

public class EmployeeConfiguration : IEntityTypeConfiguration
{
  public void Configure(EntityTypeBuilder<Employee> builder)
  {
    builder
      .Property(t => t.MySecretValue)
      .HasColumnName("my_secret_value")
      .IsEncrypted();  
  }
}
AltairCA commented 1 year ago

done :)

AltairCA commented 1 year ago

use the following extension

public class TestingConfiguration:IEntityTypeConfiguration<Testings>
{
    public void Configure(EntityTypeBuilder<Testings> builder)
    {
        builder.Property(x => x.encrypted)
            .UseEncryption("NBJ42RKQ2vQoYFZOj1C83921vHExVhVp1PlOAK6gjbMZI", EncKeyLength.L128);
    }
}
davidkeaveny commented 1 year ago

Wow, thanks for the fast turn-around on this suggestion! One small question - in your example above, you have hard-coded the encryption key; do you have any suggestions for how to make that configurable?

AltairCA commented 1 year ago

you can inject that using Configurations or using any other provider to the DbContext and then pass that to the configuration