Shaunebu.Common.Cryptography 1.0.0

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

Shaunebu.Common.Cryptography 🔐

NuGet Version

NET Support NET Support NET Support Support

Shaunebu.Common.Cryptography provides a unified cryptography API for .NET applications, supporting modern and legacy algorithms:

  • AES (CBC, GCM)

  • TripleDES

  • RSA (encrypt/decrypt, sign/verify)

  • ECDSA

  • Password hashing (PBKDF2, Argon2id)

  • Hashing (SHA256, SHA512)

  • DPAPI (Windows ProtectedData)

  • Secure password generation

It wraps the complexity of System.Security.Cryptography and Konscious.Security.Cryptography into a single, consistent, easy-to-use service.


🚀 Installation

PM> Install-Package Shaunebu.Common.Cryptography

NuGet link: Shaunebu.Common.Cryptography


⚙️ Configuration

CryptographyService.DefaultAlgorithm = EncryptionAlgorithm.AesCbc;
CryptographyService.DefaultIterations = 100_000;
CryptographyService.DefaultKeySize = 32;
  • DefaultAlgorithm: AES-CBC (default), AES-GCM, TripleDES

  • DefaultIterations: Used for PBKDF2 / Argon2id

  • DefaultKeySize: Key length in bytes (e.g., 32 = 256-bit)


🔑 Symmetric Encryption

AES / TripleDES (Encrypt / Decrypt)

var (key, iv) = ("base64Key", "base64IV");
string encrypted = CryptographyService.Cypher(CryptType.Encrypt, "Hello World", (key, iv), EncryptionAlgorithm.AesCbc);
string decrypted = CryptographyService.Cypher(CryptType.Decrypt, encrypted, (key, iv), EncryptionAlgorithm.AesCbc);

AES-GCM (Authenticated Encryption)

var key = Convert.ToBase64String(RandomNumberGenerator.GetBytes(32));
string encrypted = CryptographyService.Cypher(CryptType.Encrypt, "TopSecret", (key, ""), EncryptionAlgorithm.AesGcm);
string decrypted = CryptographyService.Cypher(CryptType.Decrypt, encrypted, (key, ""), EncryptionAlgorithm.AesGcm);

📂 File Encryption

await CryptographyService.EncryptFileAsync("plain.txt", "secret.bin", keyBytes, ivBytes);
await CryptographyService.DecryptFileAsync("secret.bin", "plain.txt", keyBytes, ivBytes);

Uses AES-CBC with PKCS7 padding.


🔐 Hashing

string hash1 = CryptographyService.Hash(HashAlgorithmType.Sha256, "data");
string hash2 = CryptographyService.Hash(HashAlgorithmType.Sha512, "data");

🔑 Password Hashing (PBKDF2 + Argon2id)

Hash a password

string stored = CryptographyService.HashPassword("MyPassword123!", PasswordHashAlgorithm.Argon2id);

Stored format:

Algorithm:Iterations:Salt:Hash

Verify a password

bool valid = CryptographyService.VerifyPassword("MyPassword123!", stored);

Supports:

  • PBKDF2-SHA256

  • PBKDF2-SHA512

  • Argon2id (recommended)


🔏 RSA

Generate Key Pair

var (pub, priv) = CryptographyService.GenerateRsaKeyPair(2048);

Encrypt / Decrypt

string cipher = CryptographyService.EncryptRsa("SecretMessage", pub);
string plain = CryptographyService.DecryptRsa(cipher, priv);

Sign / Verify

string signature = CryptographyService.SignData("Message", priv);
bool valid = CryptographyService.VerifySignature("Message", signature, pub);

📝 ECDSA

Generate Key Pair

var (pub, priv) = CryptographyService.GenerateEcdsaKeyPair();

Sign / Verify

string signature = CryptographyService.SignEcdsa("Message", priv);
bool ok = CryptographyService.VerifyEcdsa("Message", signature, pub);

🛡 Windows Data Protection (DPAPI)

Only available on Windows.

string protectedText = CryptographyService.Protect("SensitiveValue");
string plain = CryptographyService.Unprotect(protectedText);

Uses ProtectedData with CurrentUser scope.


🔐 Password Generator

string pwd1 = CryptographyService.GeneratePassword(16);            // Letters, digits, specials
string pwd2 = CryptographyService.GeneratePassword(12, false);     // Letters + digits only

📊 Supported Algorithms

Category Supported Notes
AES CBC, GCM CBC for compatibility, GCM for authenticated encryption
TripleDES CBC Legacy support
RSA Encrypt/Decrypt, Sign/Verify OAEP-SHA256 & PKCS1
ECDSA P-256 SHA256 signing
Hashing SHA256, SHA512
Password Hashing PBKDF2-SHA256, PBKDF2-SHA512, Argon2id Argon2id recommended
DPAPI Windows only Protect/Unprotect
Password Generator Random, customizable Secure RNG

✅ Example Flow

// Generate RSA key pair
var (pub, priv) = CryptographyService.GenerateRsaKeyPair();

// Encrypt and decrypt
var cipher = CryptographyService.EncryptRsa("Hello", pub);
var plain = CryptographyService.DecryptRsa(cipher, priv);

// Sign and verify
var sig = CryptographyService.SignData("Hello", priv);
var valid = CryptographyService.VerifySignature("Hello", sig, pub);

// Hash a password
var stored = CryptographyService.HashPassword("SuperSecret!");
var ok = CryptographyService.VerifyPassword("SuperSecret!", stored);

🔍 Why Use Shaunebu.Common.Cryptography?

  • Unified API: AES, RSA, ECDSA, Argon2id, PBKDF2 in one service

  • Secure defaults: Strong padding, key sizes, fixed-time compares

  • Cross-platform: Works on Windows, Linux, macOS (DPAPI only on Windows)

  • Migration-friendly: Supports multiple password algorithms

  • Production ready: Handles keys as Base64, easy to store

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
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 119 10/3/2025