EncryptionUtils.Cryptography 1.0.0

dotnet add package EncryptionUtils.Cryptography --version 1.0.0
                    
NuGet\Install-Package EncryptionUtils.Cryptography -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="EncryptionUtils.Cryptography" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EncryptionUtils.Cryptography" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="EncryptionUtils.Cryptography" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add EncryptionUtils.Cryptography --version 1.0.0
                    
#r "nuget: EncryptionUtils.Cryptography, 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.
#:package EncryptionUtils.Cryptography@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=EncryptionUtils.Cryptography&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=EncryptionUtils.Cryptography&version=1.0.0
                    
Install as a Cake Tool

🔐 EncryptionUtils

NuGet Version NuGet Downloads License

EncryptionUtils is a lightweight, modular cryptography framework for .NET — providing unified abstractions for encryption, hashing, and encryption-aware JSON serialization with minimal dependencies and maximum flexibility.


📘 Overview

EncryptionUtils is built around a simple but powerful concept: abstraction first.
Every cryptographic algorithm, hasher, and JSON converter implements one of three interfaces:

  • IEncryptionAlgorithm
  • IHasher
  • IJsonConverter

This unified design allows you to:

  • 🔄 Swap algorithms at runtime with dependency injection
  • ðŸ§Đ Mix and match implementations
  • ⚙ïļ Extend with your own algorithms easily

⚙ïļ Installation

dotnet add package EncryptionUtils.Cryptography.Algorithms
dotnet add package EncryptionUtils.Serialization.TextJson
# or
dotnet add package EncryptionUtils.Serialization.Newtonsoft

🚀 Quick Start

Example 1 — General Project Usage (AES-GCM 256)

using EncryptionUtils.Cryptography.Algorithms;

// Base64 key and IV
var key = "bVd8bJcX7v3WyqfWAWp6xPq5L9Z4Hq0QOStvzQ7XjCk=";
var iv  = "QmFzZTY0SVY=";

var aes = new AESGCM(key, iv);

string plainText = "Confidential message";
string encrypted = aes.Encrypt(plainText);
string decrypted = aes.Decrypt(encrypted);

Console.WriteLine($"Encrypted: {encrypted}");
Console.WriteLine($"Decrypted: {decrypted}");

Example 2 — Dependency Injection Setup (ASP.NET Core)

using EncryptionUtils.Cryptography.Algorithms;
using EncryptionUtils.Cryptography.Interfaces_Abstracts;
using Microsoft.Extensions.DependencyInjection;

var services = new ServiceCollection();

// Register AES-GCM 256 with DI
services.AddSingleton<IEncryptionAlgorithm>(_ =>
    new AESGCM(
        key: "bVd8bJcX7v3WyqfWAWp6xPq5L9Z4Hq0QOStvzQ7XjCk=",
        iv:  "QmFzZTY0SVY="));

var provider = services.BuildServiceProvider();
var aes = provider.GetRequiredService<IEncryptionAlgorithm>();

string data = "API secret";
string cipher = aes.Encrypt(data);
string plain  = aes.Decrypt(cipher);

Console.WriteLine($"Decrypted: {plain}");

ðŸ§Đ Key Components

Project Description
EncryptionUtils.Cryptography Core interfaces and abstract classes
EncryptionUtils.Cryptography.Algorithms AES (GCM/CBC), RSA, SHA, HMAC, Scrypt
EncryptionUtils.Serialization [Encrypt] attribute + core serialization abstractions
EncryptionUtils.Serialization.TextJson Integration with System.Text.Json
EncryptionUtils.Serialization.Newtonsoft Integration with Newtonsoft.Json

🔐 Encryption-Aware Serialization

Automatically encrypt and decrypt marked properties during JSON (de)serialization.

Example — Using System.Text.Json

using EncryptionUtils.Serialization.Attributes;

public class User
{
    public string Name { get; set; }

    [Encrypt]
    public string Password { get; set; }
}
using EncryptionUtils.Serialization.TextJson;
using EncryptionUtils.Serialization.Core;
using EncryptionUtils.Cryptography.Algorithms;

var aes = new AESGCM(256);
var converter = new TextJsonConverter();
var serializer = new EncryptedJsonSerializer(converter, aes);

var user = new User { Name = "Alice", Password = "SuperSecret" };

string json = await serializer.SerializeAsync(user);   // Password is encrypted
var restored = await serializer.DeserializeAsync<User>(json); // Password is decrypted

Example — Using Newtonsoft.Json

using EncryptionUtils.Serialization.Newtonsoft;
using EncryptionUtils.Serialization.Core;
using EncryptionUtils.Cryptography.Algorithms;
using EncryptionUtils.Serialization.Attributes;

public class Account
{
    public string Username { get; set; }

    [Encrypt]
    public string ApiKey { get; set; }
}

var aes = new AESGCM(256);
var converter = new NewtonsoftJsonConverter();
var serializer = new EncryptedJsonSerializer(converter, aes);

var account = new Account { Username = "valadis", ApiKey = "TopSecretKey" };

string json = await serializer.SerializeAsync(account);
Console.WriteLine(json); // ApiKey is encrypted

var restored = await serializer.DeserializeAsync<Account>(json);
Console.WriteLine(restored.ApiKey); // decrypted back to "TopSecretKey"

🧠 Philosophy

  • ðŸŠķ Lightweight: minimal dependencies, pure C#
  • ðŸ§Đ Modular: plug-and-play architecture
  • ðŸ’Ą Flexible: your own algorithms can implement the same interfaces
  • ⚖ïļ Consistent: identical usage patterns across all algorithm types

ðŸ“Ķ Project Structure

EncryptionUtils/
├── EncryptionUtils.Cryptography/
│   └── Interfaces_Abstracts/
├── EncryptionUtils.Cryptography.Algorithms/
├── EncryptionUtils.Serialization/
├── EncryptionUtils.Serialization.TextJson/
├── EncryptionUtils.Serialization.Newtonsoft/
└── EncryptionUtils.Tests/

⚖ïļ License


âĪïļ Contributing

Contributions and ideas are welcome!
Please open an issue or pull request on GitHub.


ðŸ‘Ļ‍ðŸ’ŧ Author

Valadis Pitsas
GitHub: @cpitsas
NuGet: EncryptionUtils.Cryptography


✅ TL;DR

A clean, consistent, and extensible cryptography abstraction layer for .NET —
simple to use, powerful to extend, and ready for production.

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.  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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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.
  • .NETStandard 2.1

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on EncryptionUtils.Cryptography:

Package Downloads
EncryptionUtils.Serialization

Serializer agnostic property serialization functionality for encrypted properties.

EncryptionUtils.Cryptography.Algorithms

Provides implementations of several cryptographic algorithms. Focused on simplicity and ease of use.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 319 10/10/2025