{"id":17484614,"url":"https://github.com/SoftFluent/EntityFrameworkCore.DataEncryption","last_synced_at":"2025-03-03T21:30:53.117Z","repository":{"id":46011534,"uuid":"174138464","full_name":"SoftFluent/EntityFrameworkCore.DataEncryption","owner":"SoftFluent","description":"A plugin for Microsoft.EntityFrameworkCore to add support of encrypted fields using built-in or custom encryption providers.","archived":false,"fork":false,"pushed_at":"2024-11-14T12:45:29.000Z","size":164,"stargazers_count":334,"open_issues_count":7,"forks_count":57,"subscribers_count":19,"default_branch":"main","last_synced_at":"2025-03-02T10:07:19.240Z","etag":null,"topics":["custom-encryption","dotnet-core","ef-core","encryption","entity-framework-core","netstandard","netstandard20","plugin"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SoftFluent.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-06T12:11:10.000Z","updated_at":"2025-02-23T14:46:01.000Z","dependencies_parsed_at":"2024-11-09T18:00:47.826Z","dependency_job_id":"290b0977-e2ae-4f03-86e6-730e0ab78501","html_url":"https://github.com/SoftFluent/EntityFrameworkCore.DataEncryption","commit_stats":{"total_commits":106,"total_committers":10,"mean_commits":10.6,"dds":0.5377358490566038,"last_synced_commit":"c54b9e150ee38535b772d8f4e82f20b47b0e3184"},"previous_names":["softfluent/entityframeworkcore.dataencryption"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoftFluent%2FEntityFrameworkCore.DataEncryption","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoftFluent%2FEntityFrameworkCore.DataEncryption/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoftFluent%2FEntityFrameworkCore.DataEncryption/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoftFluent%2FEntityFrameworkCore.DataEncryption/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SoftFluent","download_url":"https://codeload.github.com/SoftFluent/EntityFrameworkCore.DataEncryption/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241742930,"owners_count":20012717,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["custom-encryption","dotnet-core","ef-core","encryption","entity-framework-core","netstandard","netstandard20","plugin"],"created_at":"2024-10-19T01:01:36.078Z","updated_at":"2025-03-03T21:30:53.107Z","avatar_url":"https://github.com/SoftFluent.png","language":"C#","readme":"# EntityFrameworkCore.DataEncryption\n\n[![.NET](https://github.com/SoftFluent/EntityFrameworkCore.DataEncryption/actions/workflows/build.yml/badge.svg)](https://github.com/SoftFluent/EntityFrameworkCore.DataEncryption/actions/workflows/build.yml)\n[![Nuget](https://img.shields.io/nuget/v/EntityFrameworkCore.DataEncryption.svg)](https://www.nuget.org/packages/EntityFrameworkCore.DataEncryption)\n[![Nuget Downloads](https://img.shields.io/nuget/dt/EntityFrameworkCore.DataEncryption)](https://www.nuget.org/packages/EntityFrameworkCore.DataEncryption)\n\n`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.\n\n## Disclaimer\n\n\u003ch4 align=\"center\"\u003eThis project is maintained by SoftFluent\u003c/h4\u003e\u003cbr\u003e\n\nThis 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.\n\nI **do not** take responsability if you use/deploy this in a production environment and loose your encryption key or corrupt your data.\n\n## How to install\n\nInstall the package from [NuGet](https://www.nuget.org/) or from the `Package Manager Console` :\n```powershell\nPM\u003e Install-Package EntityFrameworkCore.DataEncryption\n```\n\n## Supported types\n\n| Type | Default storage type |\n|------|----------------------|\n| `string` | Base64 string |\n| `byte[]` | BINARY |\n\n## Built-in providers\n\n| Name | Class | Extra |\n|------|-------|-------|\n| [AES](https://learn.microsoft.com/en-US/dotnet/api/system.security.cryptography.aes?view=net-6.0) | [AesProvider](https://github.com/SoftFluent/EntityFrameworkCore.DataEncryption/blob/main/src/EntityFrameworkCore.DataEncryption/Providers/AesProvider.cs) | Can use a 128bits, 192bits or 256bits key |\n\n## How to use\n\n`EntityFrameworkCore.DataEncryption` supports 2 differents initialization methods:\n* Attribute\n* Fluent configuration\n\nDepending 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.\nTo use an encryption provider on your EF Core model, and enable the encryption on the `ModelBuilder`. \n\n### Example with `AesProvider` and attribute\n\n```csharp\npublic class UserEntity\n{\n\tpublic int Id { get; set; }\n\t\n\t[Encrypted]\n\tpublic string Username { get; set; }\n\t\n\t[Encrypted]\n\tpublic string Password { get; set; }\n\t\n\tpublic int Age { get; set; }\n}\n\npublic class DatabaseContext : DbContext\n{\n\t// Get key and IV from a Base64String or any other ways.\n\t// You can generate a key and IV using \"AesProvider.GenerateKey()\"\n\tprivate readonly byte[] _encryptionKey = ...; \n\tprivate readonly byte[] _encryptionIV = ...;\n\tprivate readonly IEncryptionProvider _provider;\n\n\tpublic DbSet\u003cUserEntity\u003e Users { get; set; }\n\t\n\tpublic DatabaseContext(DbContextOptions options)\n\t\t: base(options)\n\t{\n\t\t_provider = new AesProvider(this._encryptionKey, this._encryptionIV);\n\t}\n\t\n\tprotected override void OnModelCreating(ModelBuilder modelBuilder)\n\t{\n\t\tmodelBuilder.UseEncryption(_provider);\n\t}\n}\n```\nThe code bellow creates a new [`AesProvider`](https://github.com/SoftFluent/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\u003cT\u003e` of your `DbContext`.\n\n### Example with `AesProvider` and fluent configuration\n\n```csharp\npublic class UserEntity\n{\n\tpublic int Id { get; set; }\n\tpublic string Username { get; set; }\n\tpublic string Password { get; set; }\n\tpublic int Age { get; set; }\n}\n\npublic class DatabaseContext : DbContext\n{\n\t// Get key and IV from a Base64String or any other ways.\n\t// You can generate a key and IV using \"AesProvider.GenerateKey()\"\n\tprivate readonly byte[] _encryptionKey = ...; \n\tprivate readonly byte[] _encryptionIV = ...;\n\tprivate readonly IEncryptionProvider _provider;\n\n\tpublic DbSet\u003cUserEntity\u003e Users { get; set; }\n\t\n\tpublic DatabaseContext(DbContextOptions options)\n\t\t: base(options)\n\t{\n\t\t_provider = new AesProvider(this._encryptionKey, this._encryptionIV);\n\t}\n\t\n\tprotected override void OnModelCreating(ModelBuilder modelBuilder)\n\t{\n\t\t// Entities builder *MUST* be called before UseEncryption().\n\t\tvar userEntityBuilder = modelBuilder.Entity\u003cUserEntity\u003e();\n\t\t\n\t\tuserEntityBuilder.Property(x =\u003e x.Username).IsRequired().IsEncrypted();\n\t\tuserEntityBuilder.Property(x =\u003e x.Password).IsRequired().IsEncrypted();\n\n\t\tmodelBuilder.UseEncryption(_provider);\n\t}\n}\n```\n\n## Create an encryption provider\n\n`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.\n\n```csharp\npublic class MyCustomEncryptionProvider : IEncryptionProvider\n{\n\tpublic byte[] Encrypt(byte[] input)\n\t{\n\t\t// Encrypt the given input and return the encrypted data as a byte[].\n\t}\n\t\n\tpublic byte[] Decrypt(byte[] input)\n\t{\n\t\t// Decrypt the given input and return the decrypted data as a byte[].\n\t}\n}\n```\n\nTo use it, simply create a new `MyCustomEncryptionProvider` in your `DbContext` and pass it to the `UseEncryption` method:\n```csharp\npublic class DatabaseContext : DbContext\n{\n\tprivate readonly IEncryptionProvider _provider;\n\n\tpublic DatabaseContext(DbContextOptions options)\n\t\t: base(options)\n\t{\n\t\t_provider = new MyCustomEncryptionProvider();\n\t}\n\n\tprotected override void OnModelCreating(ModelBuilder modelBuilder)\n\t{\n\t\tmodelBuilder.UseEncryption(_provider);\n\t}\n}\n```\n\n## Thanks\n\nI would like to thank all the people that supports and contributes to the project and helped to improve the library. :smile:\n\n## Credits\n\nPackage Icon : from [Icons8](https://icons8.com/)\n","funding_links":[],"categories":["others","HarmonyOS"],"sub_categories":["Windows Manager"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSoftFluent%2FEntityFrameworkCore.DataEncryption","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSoftFluent%2FEntityFrameworkCore.DataEncryption","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSoftFluent%2FEntityFrameworkCore.DataEncryption/lists"}