AltairCA.EntityFrameworkCore.PostgreSQL.ColumnEncryption 3.1.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 3.1.1
NuGet\Install-Package AltairCA.EntityFrameworkCore.PostgreSQL.ColumnEncryption -Version 3.1.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="3.1.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 3.1.1
#r "nuget: AltairCA.EntityFrameworkCore.PostgreSQL.ColumnEncryption, 3.1.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=3.1.1

// Install AltairCA.EntityFrameworkCore.PostgreSQL.ColumnEncryption as a Cake Tool
#tool nuget:?package=AltairCA.EntityFrameworkCore.PostgreSQL.ColumnEncryption&version=3.1.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 netstandard2.0. The package has following dependencies

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

When you choose the version choose with the .Net Core Version for example if .Net Core version is 3.1 then choose AltairCA.EntityFrameworkCore.PostgreSQL.ColumnEncryption version 3.1.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 net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
6.0.2.3 1,536 10/20/2023
6.0.2.2 13,370 2/17/2023
6.0.2.1 8,557 3/18/2022
6.0.2 1,010 1/19/2022
6.0.1.1 423 3/18/2022
6.0.1 421 1/19/2022
6.0.0.1 408 3/18/2022
6.0.0 1,488 1/19/2022
5.0.10.2 500 3/18/2022
5.0.10.1 1,836 10/25/2021
5.0.10 395 10/24/2021
3.1.2 909 3/18/2022
3.1.1.2 417 3/18/2022
3.1.1.1 401 10/24/2021
3.1.1 378 10/24/2021
3.1.0.2 418 3/18/2022
3.1.0.1 335 10/25/2021
3.1.0 368 10/24/2021