All Projects → Eastrall → Entityframeworkcore.dataencryption

Eastrall / Entityframeworkcore.dataencryption

Licence: mit
A plugin for Microsoft.EntityFrameworkCore to add support of encrypted fields using built-in or custom encryption providers.

Projects that are alternatives of or similar to Entityframeworkcore.dataencryption

Fanray
A blog built with ASP.NET Core
Stars: ✭ 117 (+32.95%)
Mutual labels:  entity-framework-core, plugin, dotnet-core
Gofer.net
Easy C# API for Distributed Background Tasks/Jobs for .NET Core.
Stars: ✭ 383 (+335.23%)
Mutual labels:  netstandard, dotnet-core
Simplcommerce
A simple, cross platform, modularized ecommerce system built on .NET Core
Stars: ✭ 3,474 (+3847.73%)
Mutual labels:  entity-framework-core, dotnet-core
Starwars
GraphQL 'Star Wars' example using GraphQL for .NET, ASP.NET Core, Entity Framework Core
Stars: ✭ 559 (+535.23%)
Mutual labels:  entity-framework-core, dotnet-core
Moonglade
The .NET 5 blog system of https://edi.wang, runs on Microsoft Azure
Stars: ✭ 249 (+182.95%)
Mutual labels:  entity-framework-core, dotnet-core
NETProvider
Firebird ADO.NET Data Provider
Stars: ✭ 113 (+28.41%)
Mutual labels:  entity-framework-core, netstandard
Metadata Extractor Dotnet
Extracts Exif, IPTC, XMP, ICC and other metadata from image, video and audio files
Stars: ✭ 518 (+488.64%)
Mutual labels:  netstandard, dotnet-core
Linq2db.entityframeworkcore
Bring power of Linq To DB to Entity Framework Core projects
Stars: ✭ 166 (+88.64%)
Mutual labels:  entity-framework-core, dotnet-core
Pieshopcore
A simple pie shopping management system using ASP.NET CORE MVC application
Stars: ✭ 25 (-71.59%)
Mutual labels:  entity-framework-core, dotnet-core
Jetweet
Jetweet is a mini twitter clone with basic functionalities, Made using ASP.NET CORE and Entity framework technologies
Stars: ✭ 29 (-67.05%)
Mutual labels:  entity-framework-core, dotnet-core
Computesharp
A .NET 5 library to run C# code in parallel on the GPU through DX12 and dynamically generated HLSL compute shaders, with the goal of making GPU computing easy to use for all .NET developers! 🚀
Stars: ✭ 982 (+1015.91%)
Mutual labels:  netstandard, dotnet-core
Clean Architecture Manga
🌀 Clean Architecture with .NET6, C#10 and React+Redux. Use cases as central organizing structure, completely testable, decoupled from frameworks
Stars: ✭ 3,104 (+3427.27%)
Mutual labels:  entity-framework-core, dotnet-core
Run Aspnetcore
A starter kit for your next ASP.NET Core web application. Boilerplate for ASP.NET Core reference application, demonstrating a layered application architecture with applying Clean Architecture and DDD best practices. Download 100+ page eBook PDF from here ->
Stars: ✭ 227 (+157.95%)
Mutual labels:  entity-framework-core, dotnet-core
WebGPU.NET
This repository contains low-level bindings for WebGPU used in WaveEngine.
Stars: ✭ 35 (-60.23%)
Mutual labels:  dotnet-core, netstandard
Ace
Asheron's Call server emulator.
Stars: ✭ 185 (+110.23%)
Mutual labels:  entity-framework-core, dotnet-core
Akkatecture
a cqrs and event sourcing framework for dotnet core using akka.net
Stars: ✭ 414 (+370.45%)
Mutual labels:  netstandard, dotnet-core
Gajim Omemo
Gajim plugin for OMEMO Multi-End Message and Object Encryption
Stars: ✭ 84 (-4.55%)
Mutual labels:  plugin, encryption
Pomelo.entityframeworkcore.mysql
Entity Framework Core provider for MySQL and MariaDB built on top of MySqlConnector
Stars: ✭ 2,099 (+2285.23%)
Mutual labels:  entity-framework-core, dotnet-core
Storedprocedureefcore
Entity Framework Core extension to execute stored procedures
Stars: ✭ 164 (+86.36%)
Mutual labels:  entity-framework-core, dotnet-core
Steeltoe
Steeltoe .NET Core Components: CircuitBreaker, Configuration, Connectors, Discovery, Logging, Management, and Security
Stars: ✭ 612 (+595.45%)
Mutual labels:  netstandard, dotnet-core

EntityFrameworkCore.DataEncryption

Build Status Codacy Badge codecov Nuget

EntityFrameworkCore.DataEncryption is a Microsoft Entity Framework Core extension to add support of encrypted fields using built-in or custom encryption providers.

Disclaimer

This library has been developed initialy for a personal project of mine. It provides a simple way to encrypt column data.

I do not take responsability if you use this in a production environment and loose your encryption key.

How to install

Install the package from NuGet or from the Package Manager Console :

PM> Install-Package EntityFrameworkCore.DataEncryption

How to use

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.

To enable the encryption correctly, you will need to use an encryption provider, there is a list of the available providers:

Name Class Extra
AES AesProvider Can use a 128bits, 192bits or 256bits key

Example with AesProvider

public class UserEntity
{
	public int Id { get; set; }
	
	[Encrypted]
	public string Username { get; set; }
	
	[Encrypted]
	public string Password { get; set; }
	
	public int Age { get; set; }
}

public class DatabaseContext : DbContext
{
	// Get key and IV from a Base64String or any other ways.
	// You can generate a key and IV using "AesProvider.GenerateKey()"
	private readonly byte[] _encryptionKey = ...; 
	private readonly byte[] _encryptionIV = ...;
	private readonly IEncryptionProvider _provider;

	public DbSet<UserEntity> Users { get; set; }
	
	public DatabaseContext(DbContextOptions options)
		: base(options)
	{
		this._provider = new AesProvider(this._encryptionKey, this._encryptionIV);
	}
	
	protected override void OnModelCreating(ModelBuilder modelBuilder)
	{
		modelBuilder.UseEncryption(this._provider);
	}
}

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.

Create an encryption provider

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.

public class MyCustomEncryptionProvider : IEncryptionProvider
{
	public string Encrypt(string dataToEncrypt)
	{
		// Encrypt data and return as Base64 string
	}
	
	public string Decrypt(string dataToDecrypt)
	{
		// Decrypt a Base64 string to plain string
	}
}

To use it, simply create a new MyCustomEncryptionProvider in your DbContext and pass it to the UseEncryption method:

public class DatabaseContext : DbContext
{
	private readonly IEncryptionProvider _provider;

	public DatabaseContext(DbContextOptions options)
		: base(options)
	{
		this._provider = new MyCustomEncryptionProvider();
	}

	protected override void OnModelCreating(ModelBuilder modelBuilder)
	{
		modelBuilder.UseEncryption(this._provider);
	}
}

Important notes

AES Provider structure

The following section describes how encrypted fields using the built-in AES provider encrypts data.

For each encrypted field, the provider generates a new IV with a length of 16 bytes. These 16 bytes are written at the begining of the CryptoStream followed by the actual input to encrypt.

Similarly, for reading, the provider reads the first 16 bytes from the input data converted as a byte[] to retrieve the initialization vector and then read the encrypted content.

For more information, checkout the AesProvider class.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].