EntityFrameworkCore.ColumnLevelEncryption 1.0.0

dotnet add package EntityFrameworkCore.ColumnLevelEncryption --version 1.0.0                
NuGet\Install-Package EntityFrameworkCore.ColumnLevelEncryption -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EntityFrameworkCore.ColumnLevelEncryption" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EntityFrameworkCore.ColumnLevelEncryption --version 1.0.0                
#r "nuget: EntityFrameworkCore.ColumnLevelEncryption, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install EntityFrameworkCore.ColumnLevelEncryption as a Cake Addin
#addin nuget:?package=EntityFrameworkCore.ColumnLevelEncryption&version=1.0.0

// Install EntityFrameworkCore.ColumnLevelEncryption as a Cake Tool
#tool nuget:?package=EntityFrameworkCore.ColumnLevelEncryption&version=1.0.0                

EntityFrameworkCore Column-Level Encryption

Overview

This library provides a simple way to encrypt and decrypt column-level data in Entity Framework Core using an encryption provider.

Let's Connect!

I appreciate every star ⭐ that my projects receive, and your support means a lot to me! If you find my projects useful or enjoyable, please consider giving them a star.

Features

  • Automatic encryption and decryption of string properties marked with @EncryptColumn.
  • Uses AES encryption for secure data storage.
  • Easy integration with DbContext using ModelBuilder extensions.

Installation

To use this package, add the required dependencies to your .NET project:

You can install this template using NuGet:

// Install EF Core and required packages
 dotnet add package EntityFrameworkCore.ColumnLevelEncryption

Usage

1. Define the Encryption Provider & Configure the DbContext

Modify your DbContext to use the encryption provider:

using Microsoft.EntityFrameworkCore;
using EntityFrameworkCore.ColumnLevelEncryption.Util;

public class BetContext : DbContext
{
    private readonly GenerateEncryptionProvider _provider;

    public BetContext(DbContextOptions<BetContext> options) : base(options)
    {
        _provider = new GenerateEncryptionProvider("WOXcoTgvWTh+PXaYCAfiEQ==");
    }

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

2. Apply Encryption to Entity Properties

Add the @EncryptColumn attribute to properties that should be encrypted:

using EntityFrameworkCore.ColumnLevelEncryption.Attribute;

public class User
{
    public int Id { get; set; }
    
    [EncryptColumn]
    public string U_PASSWORD { get; set; }
}

How It Works

  • When Entity Framework Core interacts with the database, properties marked with @EncryptColumn are automatically encrypted before saving and decrypted when retrieved.
  • The ModelBuilderExtensions class scans all entity types and applies the encryption logic to properties with the @EncryptColumn attribute.

Security Considerations

  • The encryption key should be securely stored, not hardcoded in the application.
  • Consider using a key management service (e.g., Azure Key Vault, AWS KMS) to securely handle encryption keys.

License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 36 2/18/2025