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
<PackageReference Include="ofcoursedude.Cryptung.DependencyInjection" Version="2.1.0" />
<PackageVersion Include="ofcoursedude.Cryptung.DependencyInjection" Version="2.1.0" />
<PackageReference Include="ofcoursedude.Cryptung.DependencyInjection" />
paket add ofcoursedude.Cryptung.DependencyInjection --version 2.1.0
#r "nuget: ofcoursedude.Cryptung.DependencyInjection, 2.1.0"
#:package ofcoursedude.Cryptung.DependencyInjection@2.1.0
#addin nuget:?package=ofcoursedude.Cryptung.DependencyInjection&version=2.1.0
#tool nuget:?package=ofcoursedude.Cryptung.DependencyInjection&version=2.1.0
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
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.
Key Strength: Use strong, random passwords for your encryption keys. The example keys in this documentation are for demonstration only.
Initialization Vectors: Cryptung automatically generates a new IV for each encryption operation, ensuring that identical plaintexts produce different ciphertexts.
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 | Versions 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. |
-
.NETStandard 2.1
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)
- ofcoursedude.Cryptung (>= 2.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.