emrekizildas / EntityFrameworkCore.EncryptColumn

Encrypt & Decrypt your databases columns using EntityFramework Core.
MIT License
87 stars 40 forks source link

.NET 7, nothing happens #24

Open uenlkr4e opened 4 months ago

uenlkr4e commented 4 months ago

Hi, i am using .NET 7 and i did exactly what you described in documentation but nothing happens, my data is still saved in clear text. Am i missing something?

here is my dbcontext:

private readonly IEncryptionProvider _provider; public AppDbContext() { _provider = new GenerateEncryptionProvider("example_encrypt_key"); } ..... protected override void OnModelCreating(ModelBuilder modelBuilder) {
modelBuilder.UseEncryption(_provider); modelBuilder.ApplyConfigurationsFromAssembly(typeof(AppDbContext).Assembly);

    OnModelCreatingPartial(modelBuilder);

    base.OnModelCreating(modelBuilder);
}

and my entity model: [EncryptColumn] public string UserName { get; set; }

    [EncryptColumn]
    public string FirstName { get; set; }

    public string Email { get; set; }
uenlkr4e commented 4 months ago

anyone? i really want to use this package.

Cleax21 commented 2 months ago

Had the same problem when i tried to save my model to the database.

First thing i had to change is the example_encrypt_key value in the GenerateEncryptionProvider. I changed this to AAECAwQFBgcICQoLDA0ODw==.

Second thing is that i had to downgrade my entityframeworkcore nuget package version to 6.0.0 (Also for the .Design, .Tools and .SqlServer).

Third. i see you use a partial modelcreating OnModelCreatingPartial method, but not provided what it contains. Maybe that could also contain a issue.

Lastly. Saving data directly to the database with an insert does not encrypt / decrypt the data with the [EncryptColumn] attribute. i had to CRUD the model via the dbcontext class.

Try this for example:

AppDbContext dbContext = new();
YOURMODEL model = new()
{
    UserName = "uenlkr4e",
    FirstName = "Shane",
    Email = "Shane@gmail.com"
};
dbContext.YOURDBSET.Add(model);
dbcontext.SaveChanges()

You only have the change the YOURMODEL to the model of the data and YOURDBSET to your dbset in the AppDbContext class.

If you still have issue's, let me know ;)

karlknibbs commented 2 months ago

I ended up using EntityFrameworkCore.JamieEncryptColumn from nuget. Appears to be a fork off this project but not 100% sure, but seems to work well with EF 8.x

Cleax21 commented 2 months ago

I ended up using EntityFrameworkCore.JamieEncryptColumn from nuget. Appears to be a fork off this project but not 100% sure, but seems to work well with EF 8.x

Yeah, it is the same project, but with the use of newer packages versions for EntityFrameworkCore 8.0.0 and above.

So i will use this instead. Thanks for the tip :D