AltairCA.EntityFrameworkCore.PostgreSQL.ColumnEncryption 6.0.2.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package AltairCA.EntityFrameworkCore.PostgreSQL.ColumnEncryption --version 6.0.2.1                
NuGet\Install-Package AltairCA.EntityFrameworkCore.PostgreSQL.ColumnEncryption -Version 6.0.2.1                
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="AltairCA.EntityFrameworkCore.PostgreSQL.ColumnEncryption" Version="6.0.2.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AltairCA.EntityFrameworkCore.PostgreSQL.ColumnEncryption --version 6.0.2.1                
#r "nuget: AltairCA.EntityFrameworkCore.PostgreSQL.ColumnEncryption, 6.0.2.1"                
#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 AltairCA.EntityFrameworkCore.PostgreSQL.ColumnEncryption as a Cake Addin
#addin nuget:?package=AltairCA.EntityFrameworkCore.PostgreSQL.ColumnEncryption&version=6.0.2.1

// Install AltairCA.EntityFrameworkCore.PostgreSQL.ColumnEncryption as a Cake Tool
#tool nuget:?package=AltairCA.EntityFrameworkCore.PostgreSQL.ColumnEncryption&version=6.0.2.1                

AltairCA.EntityFrameworkCore.PostgreSQL.ColumnEncryption

AltairCA.EntityFrameworkCore.PostgreSQL.ColumnEncryption is a NPGSQL Extension that supports native PostgreSql's Raw Encryption Functions (encrypt_iv,decrypt_iv with aes-cbc/pad:pkcs) (see section F.26.4. Raw Encryption Functions). Meaning this will support search query on encrypted columns. Well, this is good if you have GDPR compliance requirement.

Note

If you use this make sure your application to the PostgreSQL service is use a encrypted connection because this will transmit the RAW PASSWORD over the network. You can enforce it in the connection string. example -

{
  "DefaultConnection": "Server=127.0.0.1;port=5432;user id=postgres;password=postgres;database=AESTester;pooling=true;Encoding=UTF8;SSL Mode=Require;Trust Server Certificate=true;"
}

take a look at SSL Mode=Require;Trust Server Certificate=true;

AltairCA.EntityFrameworkCore.PostgreSQL.ColumnEncryption targets net6.0. The package has following dependencies

<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.2.1" />

When you choose the version choose with the .Net Core Version for example if .Net Core version is 5.0 then choose AltairCA.EntityFrameworkCore.PostgreSQL.ColumnEncryption version 5.0.x

setup

NuGet install:

Install-Package AltairCA.EntityFrameworkCore.PostgreSQL.ColumnEncryption

DbContext

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            base.OnConfiguring(optionsBuilder);
            optionsBuilder.UseEncryptionFunctions("yourpassword",EncKeyLength.L128);
        }

        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);
            builder.HasPostgresExtension("pgcrypto");
            builder.UseEncryptAttribute("yourpassword",EncKeyLength.L128);
        }

Replace yourpassword with your password

Example of use

NpgsqlEncrypt Annotation Use
    public class TestModel
    {
        public string Id { get; set; } = Guid.NewGuid().ToString();
        [NpgsqlEncrypt] #Use NpgsqlEncrypt attribute to denote the property must be encrypt in database
        public string Name { get; set; }
    }
How to use it in search query
var searchTest = _dbContext.TModels.Where(x => x.Name.NpgDecrypt().Contains("test")).ToList();

Above Linq will convert to a Native Sql Query that will decrypt the column before it do a search.

You can find a example that I have used in the EncryptionTest project Tests\Tests.cs and WebApplication Project WeatherForecastController.cs

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
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
8.0.4 1,245 7/16/2024
6.0.2.3 1,844 10/20/2023
6.0.2.2 14,073 2/17/2023
6.0.2.1 8,594 3/18/2022
6.0.2 1,034 1/19/2022
6.0.1.1 447 3/18/2022
6.0.1 447 1/19/2022
6.0.0.1 432 3/18/2022
6.0.0 1,515 1/19/2022
5.0.10.2 530 3/18/2022
5.0.10.1 2,005 10/25/2021
5.0.10 636 10/24/2021
3.1.2 939 3/18/2022
3.1.1.2 443 3/18/2022
3.1.1.1 424 10/24/2021
3.1.1 404 10/24/2021
3.1.0.2 446 3/18/2022
3.1.0.1 362 10/25/2021
3.1.0 400 10/24/2021