ofcoursedude.Cryptung.DependencyInjection 2.1.0

dotnet add package ofcoursedude.Cryptung.DependencyInjection --version 2.1.0
                    
NuGet\Install-Package ofcoursedude.Cryptung.DependencyInjection -Version 2.1.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="ofcoursedude.Cryptung.DependencyInjection" Version="2.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ofcoursedude.Cryptung.DependencyInjection" Version="2.1.0" />
                    
Directory.Packages.props
<PackageReference Include="ofcoursedude.Cryptung.DependencyInjection" />
                    
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 ofcoursedude.Cryptung.DependencyInjection --version 2.1.0
                    
#r "nuget: ofcoursedude.Cryptung.DependencyInjection, 2.1.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 ofcoursedude.Cryptung.DependencyInjection@2.1.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=ofcoursedude.Cryptung.DependencyInjection&version=2.1.0
                    
Install as a Cake Addin
#tool nuget:?package=ofcoursedude.Cryptung.DependencyInjection&version=2.1.0
                    
Install as a Cake Tool

Cryptung

Cryptung is a lightweight .NET library for secure string encryption and decryption using AES-256 encryption. It provides a simple interface for encrypting sensitive data with a password-based key derivation using SHA-256.

Features

  • Secure string encryption using AES-256
  • Password-based key derivation with SHA-256
  • Automatic initialization vector (IV) generation for each encryption
  • Recryption capability to update encryption keys without decrypting to plaintext
  • Simple, fluent API design

Installation

You can install Cryptung via NuGet package manager:

# Using .NET CLI
dotnet add package Cryptung

# Using Package Manager
Install-Package Cryptung

Usage

Basic Encryption and Decryption

using Cryptung;

// Initialize with your encryption key
var encryptionKey = "The quick brown fox jumps over the lazy dog";
var cryptungService = new CryptungService(encryptionKey);

// Encrypt a string
string plainText = "Sensitive data to protect";
string encrypted = cryptungService.Encrypt(plainText);

// Decrypt the string
string decrypted = cryptungService.Decrypt(encrypted);
Console.WriteLine(decrypted); // Outputs: "Sensitive data to protect"

Key Rotation (Recryption)

When you need to update your encryption key without exposing the plaintext:

// Original encryption service
var oldKey = "Old encryption key";
var oldService = new CryptungService(oldKey);
string encryptedData = oldService.Encrypt("Sensitive data");

// New encryption service with updated key
var newKey = "New encryption key";
var newService = new CryptungService(newKey);

// Recrypt the data (decrypts with old key and encrypts with new key internally)
string recryptedData = newService.Recrypt(encryptedData, oldKey);

// Now you can decrypt with the new key
string decrypted = newService.Decrypt(recryptedData);

Security Notes

  1. Key Management: The security of your encrypted data depends on the security of your encryption key. Store it securely, preferably in a dedicated secrets management system.

  2. Key Strength: Use strong, random passwords for your encryption keys. The example keys in this documentation are for demonstration only.

  3. Initialization Vectors: Cryptung automatically generates a new IV for each encryption operation, ensuring that identical plaintexts produce different ciphertexts.

  4. Algorithm: Cryptung uses AES-256 in CBC mode with PKCS7 padding. The key is derived using SHA-256 hashing of the input password.

Dependency Injection

Cryptung includes a dependency injection package for easy integration with ASP.NET Core:

// In Startup.cs or Program.cs
services.AddCryptung("Your encryption key here");

// In your service
public class MyService
{
    private readonly ICryptungService _cryptungService;
    
    public MyService(ICryptungService cryptungService)
    {
        _cryptungService = cryptungService;
    }
    
    public void ProcessData(string sensitiveData)
    {
        string encrypted = _cryptungService.Encrypt(sensitiveData);
        // ...
    }
}

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

License

This project is licensed under the MIT License. See the LICENSE file for details.

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.

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
2.1.0 88 8/3/2025
2.0.0.80 681 12/10/2022
1.0.0.43 468 8/30/2022
1.0.0.34 474 8/5/2022
1.0.0.30 464 8/5/2022