Walter.Web.Cypher.EF 2025.2.26.1615

Prefix Reserved
dotnet add package Walter.Web.Cypher.EF --version 2025.2.26.1615                
NuGet\Install-Package Walter.Web.Cypher.EF -Version 2025.2.26.1615                
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="Walter.Web.Cypher.EF" Version="2025.2.26.1615" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Walter.Web.Cypher.EF --version 2025.2.26.1615                
#r "nuget: Walter.Web.Cypher.EF, 2025.2.26.1615"                
#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 Walter.Web.Cypher.EF as a Cake Addin
#addin nuget:?package=Walter.Web.Cypher.EF&version=2025.2.26.1615

// Install Walter.Web.Cypher.EF as a Cake Tool
#tool nuget:?package=Walter.Web.Cypher.EF&version=2025.2.26.1615                

WALTER

Introducing the WALTER Framework: Workable Algorithms for Location-aware Transmission, Encryption Response. Designed for modern developers, WALTER is a groundbreaking suite of NuGet packages crafted for excellence in .NET Standard 2.0, 2.1, Core 3.1, and .NET 6, 7, 8, as well as C++ environments. Emphasizing 100% AoT support and reflection-free operations, this framework is the epitome of performance and stability.

Whether you're tackling networking, encryption, or secure communication, WALTER offers unparalleled efficiency and precision in processing, making it an essential tool for developers who prioritize speed and memory management in their applications.

Walter.Cypher.Secure - Encrypted Data Storage

Overview

The Walter.Cypher.Secure class, part of the Walter.Web.Cypher.EF NuGet package, provides a secure way to store and manage encrypted data within an application. This is particularly useful when dealing with sensitive data, such as personally identifiable information (PII) under GDPR regulations or proprietary business data, especially when the database is hosted on a server you do not fully control (e.g., a cloud-managed database).

Key Features

  • Transparent Encryption & Decryption: Data is automatically encrypted before storage and decrypted when retrieved.
  • Data Protection Against DBAs: Even database administrators cannot access the plaintext values.
  • Searchability via Hashing: Allows for searching encrypted data using one-way deterministic hashes.
  • Entity Framework Integration: Seamlessly integrates with EF Core.
  • Optional SecureDbContext: A specialized DbContext that automatically encrypts and decrypts properties marked with the [Encrypted] attribute.

Usage Example: Invoce Class

The Invoce class extends Walter.Cypher.Secure to securely store sensitive invoice details, such as order references.

Implementation

public class Invoce : Walter.Cypher.Secure
{
    private string _orderRef;

    [Encrypted(nameof(_orderRef))]
    public string OrderRef
    {
        get => Decrypt(_orderRef);
        set
        {
            _orderRef = Encrypt(value);
            OrderRefCs = value?.GetDeterministicHashCode();
        }
    }

    public int? OrderRefCs { get; set; }
    public decimal InvoiceAmmount { get; set; }
    public decimal Discount { get; set; }
    public decimal VAT { get; set; }
    public DateTime InvouceDate { get; set; } = DateTime.Now;
    public DateTime DueData { get; set; } = DateTime.Now.AddDays(60);
    public PaymentStatus Status { get; set; }
}

Explanation

  • Field Encryption: The OrderRef property is stored encrypted in _orderRef, using the Encrypt and Decrypt methods.
  • Searchable Hashing: A deterministic hash (OrderRefCs) is stored alongside the encrypted data for search purposes.
  • Data Protection: The encryption ensures that even if the database is compromised, sensitive information remains protected.

SecureDbContext for Automatic Encryption

To simplify encryption management across multiple entity models, the SecureDbContext can be used. It automatically applies encryption and decryption for all properties marked with [Encrypted].

Implementation

public class SecureDbContext : DbContext
{
    protected void BindEncryption(ModelBuilder modelBuilder)
    {
        if (modelBuilder is null)
        {
            throw new ArgumentNullException(nameof(modelBuilder));
        }

        Hookup(modelBuilder);
    }

    private void Hookup(ModelBuilder modelBuilder)
    {
        foreach (var entityType in modelBuilder.Model.GetEntityTypes())
        {
            foreach (var property in entityType.GetProperties())
            {
                var attributes = property.PropertyInfo?.GetCustomAttributes(typeof(EncryptedAttribute), false);
                if (attributes?.Length > 0 && attributes[0] is EncryptedAttribute e)
                {
                    property.SetField(e.FieldName);
                    property.SetPropertyAccessMode(PropertyAccessMode.Field);
                }
            }
        }
    }
}

Benefits of SecureDbContext

  • Automatic Encryption Handling: Reduces manual encryption calls in entity classes.
  • Consistency: Ensures all encrypted properties follow the same rules.
  • Ease of Use: Developers only need to mark properties with [Encrypted].

How It Works

  1. Encrypting Data
    • Before storing a value in the database, it is encrypted using the Encrypt() method.
  2. Decrypting Data
    • When retrieving the value, it is decrypted using Decrypt().
  3. Searching Encrypted Data
    • Since encrypted data is not directly searchable, a deterministic hash of the original value can be stored to facilitate lookups.

Why Use Walter.Cypher.Secure?

  • Security: Ensures sensitive data is never stored in plaintext.
  • Compliance: Helps meet data protection regulations (e.g., GDPR, HIPAA).
  • Seamless Integration: Works naturally with EF Core and existing entity models.
  • Optional SecureDbContext: Provides automatic encryption handling for EF Core entities.

Installation

To use Walter.Cypher.Secure, install the Walter.Web.Cypher.EF NuGet package:

Install-Package Walter.Web.Cypher.EF

Conclusion

The Walter.Cypher.Secure class is an essential tool for securely handling sensitive data in applications where data privacy and compliance are critical. By integrating encrypted storage seamlessly into EF Core entities, it ensures that no unauthorized party—including database administrators—can access protected information. Additionally, using SecureDbContext simplifies the management of encrypted data across multiple entities, making it a powerful option for enterprise applications.

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
2025.2.26.1615 51 2/26/2025
2025.2.26.1548 42 2/26/2025
2025.2.25.528 75 2/25/2025

12 October 2023
     - Build using SDK-7.0.402 and SDK-6.0.415
     
     14 September 2023
     - SDK Service pack .net 6 and 7
     
     12 July 2023
     - Update to SDK SP 6.0.412. and 7.0.306
     
14 June 2023
- Update due to SDK Update 7.0.304, and 6.0.410

14 December 2022
- Update to .Net SDK 3.1.426, 6.0.404 and 7.0.101

31 October 2022
- Update to build with new SDK

14 September 2022
- Update to include new package 6.0.2 and Microsoft CVE-2022-38013

9 August 2022
- update to SDK 6.0.400 / .Net 6.0.8 security patch
- drop support for .net standard 2.0
- drop support for .net 5.0

15 June 2022
- Update to support .net 6.0.7 and 3.1.27

04 May 2022
- update to EF core 6.0.4

15 December 2021
- Update package references as well as .Net DSK release December 14 2021

9 November 2021
- Fix package dependency on vulnerable packages from Microsoft by upgrading vulnerable packages

8 November 2021
- Update to Microsoft packages 6.0.0, 5.0.403 and core 3.1.415

11 October 2021
- CodeSign the binaries as well as the NuGet package for executing in a trust-platform

17 September 2021
- Update NuGet Packages to the new release

8 Aug 2021
- update to .NET 6.0 SDK (v6.0.100-preview.6)

19 June 2021
- Add .Net 6.0

15 June 2021
- Update to .Net core 3.1.17 and .net 5.0.8

25 May 2021
- Update package reference external dependencies

06 March 2021
- Update Package references

01 February 2021
- Update Package references

10 February 2021
- Update package references
- Add logging interface for extracting calling file name when faced with cypher errors

25 January 2021
- Update extension methods
- Update Package references
02 January 2021
- Updated license terms
20 December 2020
- Update Package references


05 December 2020
- Update Package references

24 September 2020
1. Update package references

06  September 2020
1. Set platform x64
2. Update NuGet Package References

26 August 2020 release
1 Update dependency on NuGet packages

12 August 2020 release
1 Update dependency on NuGet packages