-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from Eastrall/wip/v4
Version 4.0.0
- Loading branch information
Showing
48 changed files
with
1,309 additions
and
2,150 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<LangVersion>10</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.10" /> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.10" /> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.10" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\EntityFrameworkCore.DataEncryption\EntityFrameworkCore.DataEncryption.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.DataEncryption; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace AesSample.Fluent; | ||
|
||
public class DatabaseContext : DbContext | ||
{ | ||
private readonly IEncryptionProvider _encryptionProvider; | ||
|
||
public DbSet<UserEntity> Users { get; set; } | ||
|
||
public DatabaseContext(DbContextOptions<DatabaseContext> options, IEncryptionProvider encryptionProvider) | ||
: base(options) | ||
{ | ||
_encryptionProvider = encryptionProvider; | ||
} | ||
|
||
protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
{ | ||
EntityTypeBuilder<UserEntity> userEntityBuilder = modelBuilder.Entity<UserEntity>(); | ||
|
||
userEntityBuilder.HasKey(x => x.Id); | ||
userEntityBuilder.Property(x => x.Id).IsRequired().ValueGeneratedOnAdd(); | ||
userEntityBuilder.Property(x => x.FirstName).IsRequired(); | ||
userEntityBuilder.Property(x => x.LastName).IsRequired(); | ||
userEntityBuilder.Property(x => x.Email).IsRequired().IsEncrypted(); | ||
userEntityBuilder.Property(x => x.Notes).IsRequired().HasColumnType("BLOB").IsEncrypted(StorageFormat.Binary); | ||
userEntityBuilder.Property(x => x.EncryptedData).IsRequired().IsEncrypted(); | ||
userEntityBuilder.Property(x => x.EncryptedDataAsString).IsRequired().HasColumnType("TEXT").IsEncrypted(StorageFormat.Base64); | ||
|
||
if (_encryptionProvider is not null) | ||
{ | ||
modelBuilder.UseEncryption(_encryptionProvider); | ||
} | ||
|
||
base.OnModelCreating(modelBuilder); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace AesSample.Fluent; | ||
|
||
public class EncryptedDatabaseContext : DatabaseContext | ||
{ | ||
public EncryptedDatabaseContext(DbContextOptions<DatabaseContext> options) | ||
: base(options, null) | ||
{ | ||
} | ||
} |
Oops, something went wrong.