Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET 7, nothing happens #24

Open
uenlkr4e opened this issue Apr 23, 2024 · 4 comments
Open

.NET 7, nothing happens #24

uenlkr4e opened this issue Apr 23, 2024 · 4 comments

Comments

@uenlkr4e
Copy link

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
Copy link
Author

anyone? i really want to use this package.

@Cleax21
Copy link

Cleax21 commented Jun 26, 2024

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 = "[email protected]"
};
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
Copy link

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
Copy link

Cleax21 commented Jun 26, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants