EasyEncrypt.NET 1.0.0

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

EasyEncrypt

Encrypt. Decrypt. Done. EasyEncrypt makes AES, RSA, ML-KEM, and hashing straightforward in C#.

All three encryption methods use the same API: generate keys → encrypt → decrypt.

Supported:

  • .NET Framework 4.7+
  • .NET Standard 2.0
  • .NET Standard 2.1
  • .NET 10

New to encryption? Start with AES-256 for data your application encrypts and decrypts itself. Use RSA or ML-KEM when someone needs to encrypt data using a public key.


Table of contents

Browse the documentation


1. Basic

Everything here works the same across supported runtimes. Only the C# syntax for resource cleanup differs in the examples.

1.1 Setup

1.1.1 Installation

1.1.1.1 .NET CLI
dotnet add package EasyEncrypt
1.1.1.2 Visual Studio

In the Package Manager Console:

Install-Package EasyEncrypt

Add the namespace to your C# file:

using System;
using EasyEncrypt;

The encryption examples below belong inside a method.

1.1.2 Framework differences

Environment Example syntax What changes?
Modern .NET (C# 8+) using EncryptKeys keys = ...; Resource cleanup happens at the end of the scope.
.NET Framework 4.7+ using (EncryptKeys keys = ...) { ... } Resource cleanup happens at the end of the block.

Both styles call Dispose() automatically. The encryption API and ciphertext format are the same. The Framework-style snippets also work on modern .NET.

1.2 AES

Use AES when your application needs to encrypt and decrypt its own data. It uses one secret key for both operations.

1.2.1 Modern .NET

using EncryptKeys keys = EncryptKeys.Generate(EncryptType.AES256);
using Encryption encryption = new Encryption(EncryptType.AES256, keys);

string encrypted = encryption.Encrypt("Hello world!");
string decrypted = encryption.Decrypt(encrypted);

Console.WriteLine(decrypted); // Hello world!

1.2.2 .NET Framework

using (EncryptKeys keys = EncryptKeys.Generate(EncryptType.AES256))
using (Encryption encryption = new Encryption(EncryptType.AES256, keys)) {
    string encrypted = encryption.Encrypt("Hello world!");
    string decrypted = encryption.Decrypt(encrypted);

    Console.WriteLine(decrypted); // Hello world!
}

What each line does: | Code | Meaning | | --- | --- | | EncryptKeys.Generate(...) | Creates a new secret key. | | new Encryption(...) | Sets up encryption with that key. | | Encrypt(...) | Turns a message into encrypted Base64 text. | | Decrypt(...) | Restores the original message. |

Important: Keep the AES key private and NOT stored in code. You need the same key to decrypt previously encrypted data.

1.3 RSA

Use RSA when someone else needs to encrypt data for you. The public key is shareable; the private key is not. Neither key should be stored in code.

1.3.1 Modern .NET

using EncryptKeys keys = EncryptKeys.Generate(EncryptType.RSA3072);
using Encryption encryption = new Encryption(EncryptType.RSA3072, keys);

string encrypted = encryption.Encrypt("Hello world!");
string decrypted = encryption.Decrypt(encrypted);

Console.WriteLine(decrypted); // Hello world!

1.3.2 .NET Framework

using (EncryptKeys keys = EncryptKeys.Generate(EncryptType.RSA3072))
using (Encryption encryption = new Encryption(EncryptType.RSA3072, keys)) {
    string encrypted = encryption.Encrypt("Hello world!");
    string decrypted = encryption.Decrypt(encrypted);

    Console.WriteLine(decrypted); // Hello world!
}

What's happening?

  1. Generate makes a matching public/private key pair.
  2. Encrypt uses the public key to protect the message.
  3. Decrypt requires the private key to recover it.

EasyEncrypt handles the underlying AES message encryption for you. To encrypt without holding the private key, see 2.1.

1.4 ML-KEM

Use ML-KEM when you want public-key encryption designed to resist attacks from future quantum computers. It uses public and private keys, just like RSA. Remember not to store key information in code.

1.4.1 Modern .NET

using EncryptKeys keys = EncryptKeys.Generate(EncryptType.MLKEM768);
using Encryption encryption = new Encryption(EncryptType.MLKEM768, keys);

string encrypted = encryption.Encrypt("Hello world!");
string decrypted = encryption.Decrypt(encrypted);

Console.WriteLine(decrypted); // Hello world!

1.4.2 .NET Framework

using (EncryptKeys keys = EncryptKeys.Generate(EncryptType.MLKEM768))
using (Encryption encryption = new Encryption(EncryptType.MLKEM768, keys)) {
    string encrypted = encryption.Encrypt("Hello world!");
    string decrypted = encryption.Decrypt(encrypted);

    Console.WriteLine(decrypted); // Hello world!
}

What's happening?

  1. Generate creates a public/private key pair.
  2. Encrypt creates a temporary shared secret and protects the message using AES.
  3. Decrypt uses the private key to recover the secret and message.

You don't need to manage those steps yourself. Use the public-key-only example in 2.1 to share a public key safely.

1.5 Hashing

Hashing is not encryption. You can check a value against a hash, but you cannot decrypt a hash back into its original value.

The following examples work unchanged on .NET Framework and modern .NET.

1.5.1 Password hashing

string storedHash = Hashing.Hash("my-password");

bool correctPassword = Hashing.Verify("my-password", storedHash);
bool wrongPassword = Hashing.Verify("incorrect-password", storedHash);

Console.WriteLine(correctPassword); // True
Console.WriteLine(wrongPassword);   // False
  • Hash(...) creates a salted password hash suitable for storing instead of the password.
  • Verify(...) checks a password against that stored hash and returns true or false.

1.5.2 SHA-256

string hash = Hashing.ComputeSha256("Hello world!");

Console.WriteLine(hash);

ComputeSha256(...) creates a Base64-encoded SHA-256 hash for comparing content. Do not use plain SHA-256 for password storage; use Hash(...) instead.

1.6 Choosing an algorithm

Choose When you need… Good starting choice
AES One application or trusted group to encrypt and decrypt data EncryptType.AES256
RSA Someone to encrypt using a public key EncryptType.RSA3072
ML-KEM Public-key encryption with post-quantum protection EncryptType.MLKEM768
Password hashing To store and check passwords Hashing.Hash(...)
SHA-256 To calculate a content fingerprint Hashing.ComputeSha256(...)

2. Advanced

These examples use the .NET Framework-compatible using (...) style, so you can use them in both .NET Framework and modern .NET projects. All declarations use explicit C# types.

2.1 Public-key-only encryption

RSA and ML-KEM let other people encrypt messages without seeing your private key.

// Change to EncryptType.MLKEM768 for ML-KEM.
EncryptType type = EncryptType.RSA3072;

using (EncryptKeys receiverKeys = EncryptKeys.Generate(type))
using (EncryptKeys senderKeys = receiverKeys.GetPublicOnly())
using (Encryption sender = new Encryption(type, senderKeys))
using (Encryption receiver = new Encryption(type, receiverKeys)) {
    string encrypted = sender.Encrypt("Private message");
    string decrypted = receiver.Decrypt(encrypted);
}

GetPublicOnly() creates a key container without the private key. The sender can encrypt, but only the receiver with the private key can decrypt.

2.2 Save and load keys

Save your keys if you need to decrypt data after the application restarts. Base64 makes keys easy to store as text; it does not make private keys safe to expose.

2.2.1 AES key

string savedKey;

using (EncryptKeys keys = EncryptKeys.Generate(EncryptType.AES256)) {
    savedKey = keys.ExportKeyBase64(KeyType.Key);
}

// Later: Read savedKey from secure storage.
using (EncryptKeys restoredKeys = new EncryptKeys(key: savedKey))
using (Encryption encryption = new Encryption(EncryptType.AES256, restoredKeys)) {
    string encrypted = encryption.Encrypt("Remember this");
    string decrypted = encryption.Decrypt(encrypted);
}

ExportKeyBase64(...) converts a key to text. new EncryptKeys(key: ...) loads it back. Store the key securely outside your source code.

2.2.2 RSA and ML-KEM key pairs

EncryptType type = EncryptType.MLKEM768;

string publicKey;
string privateKey;

using (EncryptKeys keys = EncryptKeys.Generate(type)) {
    publicKey = keys.ExportKeyBase64(KeyType.PublicKey);
    privateKey = keys.ExportKeyBase64(KeyType.PrivateKey);
}

// Later: load the saved keys.
using (EncryptKeys restoredKeys = new EncryptKeys(publicKey: publicKey, privateKey: privateKey))
using (Encryption encryption = new Encryption(type, restoredKeys)) {
    string encrypted = encryption.Encrypt("Hello again!");
    string decrypted = encryption.Decrypt(encrypted);
}

Share the public key if others need to encrypt. Store the private key securely, and never publish it. The same example works with EncryptType.RSA3072.

2.3 Bytes and objects

2.3.1 Raw bytes

Use the byte methods for data that isn't a string.

using (EncryptKeys keys = EncryptKeys.Generate(EncryptType.AES256))
using (Encryption encryption = new Encryption(EncryptType.AES256, keys)) {
    byte[] original = { 1, 2, 3, 4 };
    string encrypted = encryption.EncryptBytes(original);
    byte[] decrypted = encryption.DecryptBytes(encrypted);
}
  • EncryptBytes(...) accepts byte[] and returns encrypted Base64 text.
  • DecryptBytes(...) returns the original byte[].

2.3.2 Objects

EasyEncrypt converts an object to JSON before encrypting it.

using (EncryptKeys keys = EncryptKeys.Generate(EncryptType.AES256))
using (Encryption encryption = new Encryption(EncryptType.AES256, keys)) {
    UserRecord user = new UserRecord { Id = 42, Name = "Alex" };

    string encrypted = encryption.Encrypt(user);
    UserRecord decrypted = encryption.Decrypt<UserRecord>(encrypted);
}

Example class (outside your method):

public class UserRecord {
    public int Id { get; set; }
    public string Name { get; set; }
}

Decrypt<UserRecord>(...) recreates the object. Use Decrypt(...) for ordinary text.

2.4 Associated data

Associated data lets you tie a message to a separate value, such as a user ID or record ID. It is checked during decryption but not encrypted or included in the output.

// Add: using System.Text;
using (EncryptKeys keys = EncryptKeys.Generate(EncryptType.AES256))
using (Encryption encryption = new Encryption(EncryptType.AES256, keys)) {
    byte[] associatedData = Encoding.UTF8.GetBytes("record:42");

    string encrypted = encryption.Encrypt("Private note", associatedData);
    string decrypted = encryption.Decrypt(encrypted, associatedData);

    // A different record ID (or missing associated data) fails authentication.
}
Method What it does
Encrypt(value, associatedData) Encrypts a value and binds it to the additional data.
Decrypt(cipher, associatedData) Decrypts only if that additional data matches.
EncryptBytes(bytes, associatedData) Same behavior for raw bytes.
DecryptBytes(cipher, associatedData) Restores raw bytes when the additional data matches.

Although shown with AES, associatedData also works with RSA and ML-KEM. Maximum size: 4 KiB.

2.5 Key rotation

Use EncryptionKeyRing to encrypt new messages with a new key while still reading older messages.

using (EncryptKeys oldKeys = EncryptKeys.Generate(EncryptType.AES256))
using (EncryptKeys newKeys = EncryptKeys.Generate(EncryptType.AES256))
using (EncryptionKeyRing ring = new EncryptionKeyRing(
    "v1", EncryptType.AES256, oldKeys)) {
    string oldMessage = ring.Encrypt("Before rotation");

    ring.AddKey("v2", EncryptType.AES256, newKeys);
    ring.SetActiveKey("v2");

    string newMessage = ring.Encrypt("After rotation");
    string original = ring.Decrypt(oldMessage);
}
  • AddKey(...) registers another key under an ID.
  • SetActiveKey(...) selects the key for new messages.
  • Decrypt(...) finds the correct registered key for older messages.

Keep old keys as long as you need old data. Messages encrypted through the key ring must also be decrypted through the key ring.


3. Quick reference

3.1 Key strengths

AES RSA ML-KEM
AES128 RSA2048 MLKEM512
AES192 RSA3072 MLKEM768
AES256 RSA4096 MLKEM1024

These are EncryptType values (for example, EncryptType.AES256). The numbers mean different things for different algorithms; they are not directly comparable.

3.2 Encryption methods

Method Purpose
new Encryption(type, keys) Creates an encryptor using existing keys.
Encryption.Create(type, keys) Alternative constructor.
Encryption.CreateNew(type, out keys) Generates keys and returns an encryptor.
Encrypt(value) Encrypts text or an object into Base64 text.
Decrypt(cipher) Returns decrypted text.
Decrypt<T>(cipher) Restores a JSON-serialized object.
EncryptBytes(bytes) Encrypts a byte array into Base64 text.
DecryptBytes(cipher) Restores a byte array.

All four encryption/decryption operations accept an optional associatedData argument.

3.3 Key methods

Method Purpose
EncryptKeys.Generate(type) Generates an AES key or RSA/ML-KEM key pair.
GetPublicOnly() Copies only the public key into a new container.
ExportKey(type) Exports key bytes.
ExportKeyBase64(type) Exports a key as Base64 text.
AddKey(type, value) Adds a key to a key container.
HasKey(type) Checks whether a key exists.
Dispose() Releases owned resources and clears secret buffers where possible.

3.4 Hashing methods

Method Purpose
Hashing.Hash(password) Creates a salted PBKDF2-SHA256 password hash.
Hashing.Verify(password, storedHash) Checks a password against a saved hash.
Hashing.ComputeSha256(text) Creates a Base64 SHA-256 hash of text.
Hashing.ComputeSha256(bytes) Creates a Base64 SHA-256 hash of bytes.

4. Security and limits

Topic What to know
Save the keys You cannot decrypt stored ciphertext without the matching secret or private key.
Protect private keys Never commit secret keys to source control or write them to logs.
Public keys Safe to share for RSA and ML-KEM encryption.
Tampering Modified ciphertext or incorrect associated data causes decryption to fail.
Maximum plaintext 16 MiB per operation; no streaming-file API.
Associated data Maximum 4 KiB; authenticated but not encrypted.
AES operation limit 1,048,576 encryptions per instance; this does not track all instances using the same key.
Resource cleanup Dispose keys and encryptors. Managed-memory clearing is best-effort.

In short: Pick an algorithm, generate or restore keys, encrypt, and decrypt. Hash passwords with Hashing.Hash(...) instead of encrypting them.

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 is compatible.  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 netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 is compatible.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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
1.0.0 94 11/4/2026