![]() |
VOOZH | about |
dotnet add package DotNetBrightener.CryptoEngine --version 2026.0.2
NuGet\Install-Package DotNetBrightener.CryptoEngine -Version 2026.0.2
<PackageReference Include="DotNetBrightener.CryptoEngine" Version="2026.0.2" />
<PackageVersion Include="DotNetBrightener.CryptoEngine" Version="2026.0.2" />Directory.Packages.props
<PackageReference Include="DotNetBrightener.CryptoEngine" />Project file
paket add DotNetBrightener.CryptoEngine --version 2026.0.2
#r "nuget: DotNetBrightener.CryptoEngine, 2026.0.2"
#:package DotNetBrightener.CryptoEngine@2026.0.2
#addin nuget:?package=DotNetBrightener.CryptoEngine&version=2026.0.2Install as a Cake Addin
#tool nuget:?package=DotNetBrightener.CryptoEngine&version=2026.0.2Install as a Cake Tool
Copyright © 2017 - 2026 Vampire Coder (formerly DotnetBrightener)
A library providing APIs for asymmetric and symmetric encryption methods in .NET applications.
dotnet add package DotNetBrightener.CryptoEngine
IPasswordValidationProviderusing DotNetBrightener.CryptoEngine;
using DotNetBrightener.CryptoEngine.Loaders;
using DotNetBrightener.CryptoEngine.Options;
// Configure crypto engine
builder.Services.Configure<CryptoEngineConfiguration>(options =>
{
options.RsaKeyLoader = "FileLoader"; // or "EnvVarLoader"
options.RsaEnvironmentVariableName = "RSAPrivateKey"; // for EnvVarLoader
});
// Register loaders
builder.Services.AddSingleton<FileRSAKeysLoader>();
builder.Services.AddSingleton<EnvironmentVarISAKeysLoader>();
// Register crypto services
builder.Services.AddSingleton<ICryptoEngine, DefaultCryptoEngine>();
builder.Services.AddSingleton<IPasswordValidationProvider, DefaultPasswordValidationProvider>();
public class MyService
{
private readonly ICryptoEngine _cryptoEngine;
public MyService(ICryptoEngine cryptoEngine)
{
_cryptoEngine = cryptoEngine;
_cryptoEngine.Initialize();
}
public void Example()
{
string plainText = "Sensitive data";
// Encrypt with system key
string encrypted = _cryptoEngine.EncryptText(plainText);
// Decrypt with system key
string decrypted = _cryptoEngine.DecryptText(encrypted);
// Sign data
string signature = _cryptoEngine.SignData(plainText);
// Verify signature
bool isValid = _cryptoEngine.VerifyData(plainText, signature);
// Get public key for sharing
string publicKey = _cryptoEngine.GetPublicKey();
}
}
Static class providing RSA encryption operations.
using DotNetBrightener.CryptoEngine;
// Generate new RSA key pair (2048-bit)
var (publicKey, privateKey) = RsaCryptoEngine.GenerateKeyPair();
// Generate without PEM headers (inline string)
var (publicKeyInline, privateKeyInline) = RsaCryptoEngine.GenerateKeyPair(inlineString: true);
string plainText = "Hello, World!";
string publicKey = "..."; // PEM or XML format
// Encrypt with public key
string encrypted = RsaCryptoEngine.EncryptString(plainText, publicKey);
// Decrypt with private key
string privateKey = "...";
string decrypted = RsaCryptoEngine.DecryptString(encrypted, privateKey);
// Encrypt file
RsaCryptoEngine.EncryptFile(@"C:\plain.txt", publicKey, @"C:\encrypted.txt");
// Decrypt file
RsaCryptoEngine.DecryptFile(@"C:\encrypted.txt", privateKey, @"C:\decrypted.txt");
string message = "Data to sign";
// Sign with private key
string signature = RsaCryptoEngine.SignData(message, privateKey);
// Verify with public key
bool isValid = RsaCryptoEngine.VerifyData(message, signature, publicKey);
bool isValid = RsaCryptoEngine.ValidateKeyPair(publicKey, privateKey);
// Import from PEM format
var csp = RsaCryptoEngine.ImportPemPublicKey(publicKeyPem);
var csp = RsaCryptoEngine.ImportPemPrivateKey(privateKeyPem);
// Import from XML format
var csp = RsaCryptoEngine.ImportFromXml(xmlContent);
// Export to PEM format
string publicKeyPem = csp.ExportPublicKeyToPem();
string privateKeyPem = csp.ExportPrivateKeyToPem();
// Export as inline string (no PEM headers)
string publicKeyInline = csp.ExportPublicKeyToPem(inlineString: true);
Recommended symmetric encryption using AES algorithm. Supports key sizes of 128, 192, or 256 bits.
using DotNetBrightener.CryptoEngine;
string plainText = "Secret message";
string key = "MyEncryptionKey123"; // Max 32 characters
// Encrypt
string encrypted = AesCryptoEngine.Encrypt(plainText, key);
// Decrypt
string decrypted = AesCryptoEngine.Decrypt(encrypted, key);
// Safe decrypt (returns false on failure)
if (AesCryptoEngine.TryDecrypt(encrypted, out string result, key))
{
Console.WriteLine($"Decrypted: {result}");
}
The encryption key length determines the AES key size:
| Key Length | AES Key Size |
|---|---|
| ⇐ 16 chars | 128-bit |
| 17-24 chars | 192-bit |
| 25-32 chars | 256-bit |
Note: Maximum key length is 32 characters.
Warning: TripleDES is deprecated. Use
AesCryptoEnginefor new implementations.
using DotNetBrightener.CryptoEngine;
string plainText = "Secret message";
string key = "EncryptionKey";
// Encrypt
string encrypted = TripleDesCryptoEngine.Encrypt(plainText, key);
// Decrypt
string decrypted = TripleDesCryptoEngine.Decrypt(encrypted, key);
// Safe decrypt
bool success = TripleDesCryptoEngine.TryDecrypt(encrypted, out string result, key);
using DotNetBrightener.CryptoEngine;
// Generate with random size
string salt = PasswordUtilities.CreatePasswordSalt();
// Generate with specific size
string salt = PasswordUtilities.CreatePasswordSalt(saltSize: 32);
// Alphanumeric string
string random = PasswordUtilities.GenerateRandomString(length: 16);
// Include symbols
string withSymbols = PasswordUtilities.GenerateRandomString(length: 16, includeSymbols: true);
// Numeric only
string numeric = PasswordUtilities.GenerateRandomNumericString(length: 6); // OTP codes
// Equivalent to JavaScript btoa()
string encoded = PasswordUtilities.JsBtoAString("input string");
// Equivalent to JavaScript atob()
string decoded = PasswordUtilities.JsAtoBString(encoded);
using DotNetBrightener.CryptoEngine;
// Generate random token
string token = CryptoUtilities.CreateRandomToken(64);
// Let system choose random size
string token = CryptoUtilities.CreateRandomToken(0);
string originalToken = null;
// Generate token that expires in 5 minutes (default)
string timeToken = CryptoUtilities.GenerateTimeBasedToken(ref originalToken);
// Generate token with custom expiration
string timeToken = CryptoUtilities.GenerateTimeBasedToken(ref originalToken, TimeSpan.FromHours(1));
// Validate token
if (CryptoUtilities.ValidateTimeBasedToken(timeToken, out string tokenData))
{
Console.WriteLine($"Valid! Token data: {tokenData}");
}
else
{
Console.WriteLine("Token expired or invalid");
}
public interface IPasswordValidationProvider
{
/// <summary>
/// Generates an encrypted password and its associated key
/// </summary>
Tuple<string, string> GenerateEncryptedPassword(string plainTextPassword);
/// <summary>
/// Validates the plain text password
/// </summary>
bool ValidatePassword(string plainTextPassword, string passwordEncryptionKey, string hashedPassword);
}
public class UserService
{
private readonly IPasswordValidationProvider _passwordProvider;
public UserService(IPasswordValidationProvider passwordProvider)
{
_passwordProvider = passwordProvider;
}
public void RegisterUser(string email, string password)
{
var (encryptedKey, hashedPassword) = _passwordProvider.GenerateEncryptedPassword(password);
// Store encryptedKey and hashedPassword in database
// encryptedKey = password salt (encrypted with RSA)
// hashedPassword = AES encrypted password with the salt
}
public bool VerifyPassword(string email, string inputPassword, string storedKey, string storedHash)
{
return _passwordProvider.ValidatePassword(inputPassword, storedKey, storedHash);
}
}
Loads or generates RSA keys from files in enc_keys/ folder.
builder.Services.AddSingleton<FileRSAKeysLoader>(sp =>
new FileRSAKeysLoader("/path/to/app/root"));
Keys are stored as:
enc_keys/public.key - Public key (PEM format)enc_keys/private.key - Private key (PEM format)Loads RSA keys from environment variables.
builder.Services.Configure<CryptoEngineConfiguration>(options =>
{
options.RsaKeyLoader = "EnvVarLoader";
options.RsaEnvironmentVariableName = "MY_RSA_PRIVATE_KEY";
});
Set the environment variable:
# Linux/macOS
export MY_RSA_PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----..."
# Windows PowerShell
$env:MY_RSA_PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----..."
# Azure App Service
# Add Application Setting: MY_RSA_PRIVATE_KEY
public class CryptoEngineConfiguration
{
/// <summary>
/// Name of the RSA key loader to use: "FileLoader" or "EnvVarLoader"
/// </summary>
public string RsaKeyLoader { get; set; }
/// <summary>
/// Environment variable name for RSA private key (default: "RSAPrivateKey")
/// </summary>
public string RsaEnvironmentVariableName { get; set; } = "RSAPrivateKey";
}
{
"CryptoEngineConfiguration": {
"RsaKeyLoader": "EnvVarLoader",
"RsaEnvironmentVariableName": "RSA_PRIVATE_KEY"
}
}
Microsoft.Extensions.ConfigurationMicrosoft.Extensions.Logging.AbstractionsMicrosoft.Extensions.OptionsPortable.BouncyCastle - For PEM key handlingSystem.Security.Cryptography.XmlKey Storage: Store private keys securely. Use environment variables or secure key vaults in production.
AES Key Length: Use 32-character keys for AES-256 encryption.
Deprecated Algorithms: Avoid TripleDesCryptoEngine and SymmetricCryptoEngine for new implementations.
Password Storage: Always use IPasswordValidationProvider for password hashing - it combines RSA and AES encryption.
Key Rotation: Implement key rotation policies for long-running applications.
| Class | Description |
|---|---|
ICryptoEngine |
Main interface for encryption operations |
DefaultCryptoEngine |
Default implementation using RSA encryption |
RsaCryptoEngine |
Static RSA encryption utilities |
AesCryptoEngine |
Static AES encryption utilities |
TripleDesCryptoEngine |
Static TripleDES encryption (deprecated) |
CryptoUtilities |
Token generation utilities |
PasswordUtilities |
Password-related utilities |
IPasswordValidationProvider |
Password hashing interface |
IRSAKeysLoader |
RSA key loading interface |
FileRSAKeysLoader |
File-based key loader |
EnvironmentVarISAKeysLoader |
Environment variable key loader |
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 5 NuGet packages that depend on DotNetBrightener.CryptoEngine:
| Package | Downloads |
|---|---|
|
DotNetBrightener.Infrastructure.Security
A library that provides the abilities to authorize the users with given permissions |
|
|
DotNetBrightener.CryptoEngine.DependencyInjection
A library that helps configuring DotNetBrightener.CryptoEngine in ASP.Net Core applications with minimal efforts |
|
|
DotNetBrightener.Infrastructure.JwtAuthentication
Package Description |
|
|
DotNetBrightener.Infrastructure.ApiKeyAuthentication
Package Description |
|
|
DotNetBrightener.WebApp.CommonShared
Package Description |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2026.0.3-preview-777 | 193 | 5/20/2026 |
| 2026.0.3-preview-773 | 166 | 4/24/2026 |
| 2026.0.3-preview-772 | 201 | 4/3/2026 |
| 2026.0.3-preview-770 | 163 | 4/2/2026 |
| 2026.0.3-preview-769 | 152 | 4/2/2026 |
| 2026.0.2 | 636 | 4/2/2026 |
| 2026.0.2-preview-v2026-0-1-755 | 169 | 3/27/2026 |
| 2026.0.2-preview-759 | 168 | 4/1/2026 |
| 2026.0.2-preview-758 | 157 | 3/29/2026 |
| 2026.0.2-preview-757 | 161 | 3/29/2026 |
| 2026.0.2-preview-756 | 155 | 3/27/2026 |
| 2026.0.2-preview-754 | 149 | 3/27/2026 |
| 2026.0.1 | 199 | 3/27/2026 |
| 2026.0.1-preview-752 | 153 | 3/26/2026 |
| 2026.0.1-preview-750 | 157 | 3/26/2026 |
| 2026.0.1-preview-749 | 152 | 3/25/2026 |
| 2025.0.11-preview-776 | 215 | 5/20/2026 |
| 2025.0.11-preview-771 | 195 | 4/2/2026 |
| 2025.0.11-preview-768 | 191 | 4/2/2026 |
| 2025.0.11-preview-762 | 202 | 4/2/2026 |