You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`EntityFrameworkCore.DataEncryption` is a [Microsoft Entity Framework Core](https://github.com/aspnet/EntityFrameworkCore) extension to add support of encrypted fields using built-in or custom encryption providers.
8
9
9
10
## Disclaimer
10
11
11
-
This library has been developed initialy for a personal project of mine. It provides a simple way to encrypt column data.
12
+
<h4align="center">:warning: This project is **not** affiliated with Microsoft. :warning:</h4><br>
12
13
13
-
I **do not** take responsability if you use this in a production environment and loose your encryption key.
14
+
This library has been developed initialy for a personal project of mine which suits my use case. It provides a simple way to encrypt column data.
15
+
16
+
I **do not** take responsability if you use/deploy this in a production environment and loose your encryption key or corrupt your data.
14
17
15
18
## How to install
16
19
@@ -19,17 +22,29 @@ Install the package from [NuGet](https://www.nuget.org/) or from the `Package Ma
To use `EntityFrameworkCore.DataEncryption`, you will need to decorate your `string` properties of your entities with the `[Encrypted]` attribute and enable the encryption on the `ModelBuilder`.
27
+
| Type | Default storage type |
28
+
|------|----------------------|
29
+
|`string`| Base64 string |
30
+
|`byte[]`| BINARY |
25
31
26
-
To enable the encryption correctly, you will need to use an **encryption provider**, there is a list of the available providers:
32
+
## Built-in providers
27
33
28
34
| Name | Class | Extra |
29
35
|------|-------|-------|
30
-
|[AES](https://docs.microsoft.com/en-US/dotnet/api/system.security.cryptography.aes?view=netcore-2.2)|[AesProvider](https://github.com/Eastrall/EntityFrameworkCore.DataEncryption/blob/master/src/EntityFrameworkCore.DataEncryption/Providers/AesProvider.cs)| Can use a 128bits, 192bits or 256bits key |
36
+
|[AES](https://learn.microsoft.com/en-US/dotnet/api/system.security.cryptography.aes?view=net-6.0)|[AesProvider](https://github.com/Eastrall/EntityFrameworkCore.DataEncryption/blob/main/src/EntityFrameworkCore.DataEncryption/Providers/AesProvider.cs)| Can use a 128bits, 192bits or 256bits key |
Depending on the initialization method you will use, you will need to decorate your `string` or `byte[]` properties of your entities with the `[Encrypted]` attribute or use the fluent `IsEncrypted()` method in your model configuration process.
45
+
To use an encryption provider on your EF Core model, and enable the encryption on the `ModelBuilder`.
46
+
47
+
### Example with `AesProvider` and attribute
33
48
34
49
```csharp
35
50
publicclassUserEntity
@@ -58,34 +73,72 @@ public class DatabaseContext : DbContext
The code bellow creates a new `AesEncryption` provider and gives it to the current model. It will encrypt every `string` fields of your model that has the `[Encrypted]` attribute when saving changes to database. As for the decrypt process, it will be done when reading the `DbSet<T>` of your `DbContext`.
85
+
The code bellow creates a new [`AesProvider`](https://github.com/Eastrall/EntityFrameworkCore.DataEncryption/blob/main/src/EntityFrameworkCore.DataEncryption/Providers/AesProvider.cs) and gives it to the current model. It will encrypt every `string` fields of your model that has the `[Encrypted]` attribute when saving changes to database. As for the decrypt process, it will be done when reading the `DbSet<T>` of your `DbContext`.
71
86
72
-
## Create an encryption provider
87
+
### Example with `AesProvider` and fluent configuration
88
+
89
+
```csharp
90
+
publicclassUserEntity
91
+
{
92
+
publicintId { get; set; }
93
+
publicstringUsername { get; set; }
94
+
publicstringPassword { get; set; }
95
+
publicintAge { get; set; }
96
+
}
73
97
74
-
> :warning: This section is outdated and doesn't work for V3.0.0 and will be updated soon.
98
+
publicclassDatabaseContext : DbContext
99
+
{
100
+
// Get key and IV from a Base64String or any other ways.
101
+
// You can generate a key and IV using "AesProvider.GenerateKey()"
`EntityFrameworkCore.DataEncryption` gives the possibility to create your own encryption providers. To do so, create a new class and make it inherit from `IEncryptionProvider`. You will need to implement the `Encrypt(string)` and `Decrypt(string)` methods.
0 commit comments