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
To use `EntityFrameworkCore.DataEncryption`, you will need to decorate your `string` or `byte[]` properties of your entities with the `[Encrypted]` attribute and enable the encryption on the `ModelBuilder`.
25
+
| Type | Default storage type |
26
+
|------|----------------------|
27
+
|`string`| Base64 string |
28
+
|`byte[]`| BINARY |
26
29
27
-
To enable the encryption correctly, you will need to use an **encryption provider**, there is a list of the available providers:
30
+
## Built-in providers
28
31
29
32
| Name | Class | Extra |
30
33
|------|-------|-------|
31
34
|[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.
43
+
To use an encryption provider on your EF Core model, and enable the encryption on the `ModelBuilder`.
44
+
45
+
### Example with `AesProvider` and attribute
34
46
35
47
```csharp
36
48
publicclassUserEntity
@@ -59,16 +71,55 @@ public class DatabaseContext : DbContext
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`.
84
+
85
+
### Example with `AesProvider` and fluent configuration
86
+
87
+
```csharp
88
+
publicclassUserEntity
89
+
{
90
+
publicintId { get; set; }
91
+
publicstringUsername { get; set; }
92
+
publicstringPassword { get; set; }
93
+
publicintAge { get; set; }
94
+
}
95
+
96
+
publicclassDatabaseContext : DbContext
97
+
{
98
+
// Get key and IV from a Base64String or any other ways.
99
+
// You can generate a key and IV using "AesProvider.GenerateKey()"
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`.
72
123
73
124
## Create an encryption provider
74
125
@@ -98,12 +149,12 @@ public class DatabaseContext : DbContext
0 commit comments