SimpleEncryption 1.1.2

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

SimpleEncryption

SimpleEncryption is a modular library for cryptographic operations, designed to make encryption, hashing, and key derivation simple, flexible, and efficient.


✨ Features

  • 🔒 Encryption:
    • AES (256-bit) with configurable cipher modes and padding.
    • ChaCha20-Poly1305 for authenticated encryption.
  • 🔑 Hashing:
    • Secure hashing algorithms: SHA-256 and SHA-512.
  • 🧬 Key Derivation:
    • PBKDF2 key derivation.
  • ⚙️ Salt and Nonce Generation:
    • Generate secure salts and nonces dynamically.
  • 💡 Thread-safe and configurable.
  • ⚠️ OS Compatibility Notes:
    • ChaCha20 is not supported on iOS, tvOS, and browser environments.
    • AES is not supported on browser environments.

📚 Installation

Install SimpleEncryption via NuGet:

dotnet add package SimpleEncryption

📚 Overview

🔒 AES Encryption

Encrypt and decrypt strings and byte arrays using AES (256-bit):

using SimpleEncryption.Encryption;

byte[] key = Aes.GenerateKey("password", "salt");
byte[] iv = Aes.GenerateIv("password", "salt");

// Encrypt a string
string encrypted = Aes.Encrypt("Hello, World!", key, iv);
string decrypted = Aes.Decrypt(encrypted, key, iv);

// Encrypt a byte array
byte[] encryptedBytes = Aes.Encrypt(Encoding.UTF8.GetBytes("Hello, World!"), key, iv);
byte[] decryptedBytes = Aes.Decrypt(encryptedBytes, key, iv);

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

ChaCha20-Poly1305 Encryption

Lightweight and secure encryption with associated data (AAD):

using SimpleEncryption.Encryption;

byte[] key = ChaCha20.GenerateKey("password", "salt");
byte[] nonce = ChaCha20.GenerateNonce();

// Encrypt a string
string encrypted = ChaCha20.Encrypt("Hello, World!", key, nonce);
string decrypted = ChaCha20.Decrypt(encrypted, key, nonce);

// Encrypt a byte array
byte[] encryptedBytes = ChaCha20.Encrypt(Encoding.UTF8.GetBytes("Hello, World!"), key, nonce);
byte[] decryptedBytes = ChaCha20.Decrypt(encryptedBytes, key, nonce);

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

🔑 Hashing (SHA-256 and SHA-512)

Hash strings securely with or without salt:

using SimpleEncryption.Hashing;

// Hash a string
string sha256Hash = Sha256.Hash("password");
string sha512Hash = Sha512.Hash("password");

// Hash a string with salt
string sha256Salted = Sha256.Hash("password", "salt");
string sha512Salted = Sha512.Hash("password", "salt");

Console.WriteLine($"SHA-256 Hash: {sha256Hash}");
Console.WriteLine($"SHA-512 Hash: {sha512Hash}");

🧬 PBKDF2 Key Derivation

Derive secure keys:

using SimpleEncryption.Derivation;

byte[] salt = Encoding.UTF8.GetBytes("random_salt");

// Derive a key from a password
string derivedKey = Pbkdf2.DeriveKey("password", salt);
byte[] derivedKeyBytes = Pbkdf2.DeriveKey(Encoding.UTF8.GetBytes("password"), salt);

Console.WriteLine($"Derived Key: {derivedKey}");

🤝 Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request on GitHub.


🐝 OS Compatibility

  • ChaCha20-Poly1305 is not supported on:
    • iOS
    • tvOS
    • browser environments
  • AES Encryption is not supported on:
    • browser environments

🐝 License

This project is licensed under the MIT License.

⚠️ Security & Disclaimer

This library has been developed with the goal of providing the highest possible security in encryption, hashing, and key derivation algorithms. However:

  • There is no guarantee that the implementation is completely free of vulnerabilities.
  • Use this library at your own risk.
  • No warranty is provided regarding its suitability for critical security applications or highly sensitive environments.

If you intend to use this library in a security-sensitive environment, it is strongly recommended to conduct additional security audits and follow best cryptographic practices.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-android34.0 is compatible.  net8.0-browser was computed.  net8.0-browser1.0 is compatible.  net8.0-ios was computed.  net8.0-ios18.0 is compatible.  net8.0-maccatalyst was computed.  net8.0-maccatalyst18.0 is compatible.  net8.0-macos was computed.  net8.0-macos15.0 is compatible.  net8.0-tvos was computed.  net8.0-tvos18.0 is compatible.  net8.0-windows was computed.  net8.0-windows7.0 is compatible.  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.
  • net8.0

    • No dependencies.
  • net8.0-android34.0

    • No dependencies.
  • net8.0-browser1.0

    • No dependencies.
  • net8.0-ios18.0

    • No dependencies.
  • net8.0-maccatalyst18.0

    • No dependencies.
  • net8.0-macos15.0

    • No dependencies.
  • net8.0-tvos18.0

    • No dependencies.
  • net8.0-windows7.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on SimpleEncryption:

Package Downloads
SimpleFiles

The SimpleFiles is a powerful and easy-to-use solution for handling file and folder operations in .NET. With built-in encryption and flexibility, it simplifies file management while keeping your data secure. 🔒

SimpleSecureData

SimpleSecureData is a library designed to provide enhanced security for local applications by ensuring data remains encrypted in memory at all times. It uses platform-specific secure storage mechanisms

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.2 126 11 days ago
1.1.1 152 11 days ago
1.1.0 100 3 months ago
1.0.3 130 3 months ago
1.0.2 91 3 months ago
1.0.1 87 3 months ago
1.0.0 98 3 months ago

- Added HMAC support for SHA512 and SHA256.
- Updated HMAC support fot AES. Now you can insert yout own HMAC key.