Ecng.Security 1.0.269

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

Ecng.Security

A comprehensive .NET library providing cryptography helpers for hashing, encryption, and secure password storage. This library simplifies common cryptographic scenarios such as AES encryption, RSA key handling, digital signatures, and password verification.

Table of Contents

Installation

Add a reference to the Ecng.Security assembly in your project.

<PackageReference Include="Ecng.Security" Version="x.x.x" />

Features

  • Simple Hashing Extensions: MD5, SHA256, SHA512 with one-liner syntax
  • AES Symmetric Encryption: Easy-to-use AES encryption with PBKDF2 key derivation
  • RSA Asymmetric Encryption: RSA encryption/decryption with parameter conversion utilities
  • Digital Signatures: Create and verify RSA/DSA signatures
  • Secure Password Storage: Salted password hashing with the Secret class
  • X.509 Certificate Support: Simplified cryptography using X.509 certificates
  • Authorization Helpers: Built-in authorization modules for login validation
  • Cross-Platform: Supports .NET Standard 2.0, .NET 6.0, and .NET 10.0

Quick Start

Hash a String

using Ecng.Security;
using Ecng.Common;

byte[] data = "Hello, World!".UTF8();
string hash = data.Sha256();
Console.WriteLine(hash); // Outputs the SHA256 hash as a hex string

Encrypt and Decrypt Data

using Ecng.Security;
using Ecng.Common;

// Prepare encryption parameters
byte[] plainText = "Sensitive data".UTF8();
string password = "MySecretPassword";
byte[] salt = TypeHelper.GenerateSalt(CryptoHelper.DefaultSaltSize);
byte[] iv = new byte[16]; // 16 bytes for AES

// Encrypt
byte[] encrypted = plainText.EncryptAes(password, salt, iv);

// Decrypt
byte[] decrypted = encrypted.DecryptAes(password, salt, iv);
string result = decrypted.UTF8();
Console.WriteLine(result); // Outputs: "Sensitive data"

Store and Validate Passwords

using Ecng.Security;

// Create a password hash
Secret secret = "MyPassword123".CreateSecret(CryptoAlgorithm.Create(AlgorithmTypes.Hash));

// Validate password
bool isValid = secret.IsValid("MyPassword123", CryptoAlgorithm.Create(AlgorithmTypes.Hash));
Console.WriteLine(isValid); // Outputs: True

bool isInvalid = secret.IsValid("WrongPassword", CryptoAlgorithm.Create(AlgorithmTypes.Hash));
Console.WriteLine(isInvalid); // Outputs: False

API Reference

Hashing

The library provides extension methods for common hashing algorithms:

Md5(byte[] value)

Computes the MD5 hash of the input data.

using Ecng.Security;
using Ecng.Common;

byte[] data = "Hello".UTF8();
string md5Hash = data.Md5();
Sha256(byte[] value)

Computes the SHA256 hash of the input data.

byte[] data = "Hello".UTF8();
string sha256Hash = data.Sha256();
Sha512(byte[] value)

Computes the SHA512 hash of the input data.

byte[] data = "Hello".UTF8();
string sha512Hash = data.Sha512();

Comparison with Standard .NET:

Standard .NET approach:

using var md5 = MD5.Create();
var hash = Convert.ToHexString(md5.ComputeHash(data));

With Ecng.Security:

var hash = data.Md5();

AES Encryption

AES (Advanced Encryption Standard) is a symmetric encryption algorithm. The library uses PBKDF2 for key derivation and CBC mode with PKCS7 padding.

EncryptAes(byte[] plain, string passPhrase, byte[] salt, byte[] iv)

Encrypts data using AES with a password-based key.

Parameters:

  • plain: The plaintext data to encrypt
  • passPhrase: The password/passphrase for key derivation
  • salt: Salt for PBKDF2 (recommended: 128 bytes)
  • iv: Initialization vector (16 bytes for AES)

Returns: Encrypted bytes

using Ecng.Security;
using Ecng.Common;

byte[] plainText = "Confidential information".UTF8();
string password = "StrongPassword!";
byte[] salt = TypeHelper.GenerateSalt(128);
byte[] iv = new byte[16];

byte[] encrypted = plainText.EncryptAes(password, salt, iv);
DecryptAes(byte[] cipherText, string passPhrase, byte[] salt, byte[] iv)

Decrypts AES-encrypted data.

Parameters:

  • cipherText: The encrypted data
  • passPhrase: The password/passphrase used for encryption
  • salt: Salt used during encryption
  • iv: Initialization vector used during encryption

Returns: Decrypted bytes

byte[] decrypted = encrypted.DecryptAes(password, salt, iv);
string original = decrypted.UTF8();

Important Notes:

  • Store the salt and iv securely alongside the encrypted data
  • Use TypeHelper.GenerateSalt(size) to generate cryptographically secure random salt
  • The IV must be exactly 16 bytes for AES
  • The same salt, iv, and passPhrase must be used for both encryption and decryption

Complete Example:

using Ecng.Security;
using Ecng.Common;

// Setup
byte[] plainText = "Top Secret Data".UTF8();
string password = "SecureP@ssw0rd";
byte[] salt = TypeHelper.GenerateSalt(CryptoHelper.DefaultSaltSize); // 128 bytes
byte[] iv = new byte[16];

// Encrypt
byte[] encrypted = plainText.EncryptAes(password, salt, iv);

// In real applications, store encrypted, salt, and iv
// For example, in a database or file

// Decrypt
byte[] decrypted = encrypted.DecryptAes(password, salt, iv);
Console.WriteLine(decrypted.UTF8()); // Outputs: "Top Secret Data"

Password Storage

The Secret class provides secure password storage using salted hashing.

CreateSecret(string plainText, CryptoAlgorithm algo)

Creates a new Secret from a plaintext password.

Parameters:

  • plainText: The password to hash
  • algo: The cryptographic algorithm to use (typically a hash algorithm)

Returns: A Secret object containing the salt and hash

using Ecng.Security;

// Create hash algorithm
var hashAlgo = CryptoAlgorithm.Create(AlgorithmTypes.Hash);

// Create secret from password
Secret secret = "UserPassword123".CreateSecret(hashAlgo);

// Store secret.Salt and secret.Hash in your database
IsValid(Secret secret, string password, CryptoAlgorithm algo)

Validates a password against a stored Secret.

Parameters:

  • secret: The stored secret
  • password: The password to validate
  • algo: The algorithm used to create the secret

Returns: true if the password is valid, false otherwise

var hashAlgo = CryptoAlgorithm.Create(AlgorithmTypes.Hash);

// Later, when validating login
bool isValid = secret.IsValid("UserPassword123", hashAlgo);

if (isValid)
{
    Console.WriteLine("Login successful!");
}
else
{
    Console.WriteLine("Invalid password!");
}

Overloads with SecureString:

using System.Security;

SecureString securePassword = new SecureString();
foreach (char c in "password")
    securePassword.AppendChar(c);
securePassword.MakeReadOnly();

Secret secret = securePassword.CreateSecret(hashAlgo);
bool isValid = secret.IsValid(securePassword, hashAlgo);

Complete Password Storage Example:

using Ecng.Security;

public class UserService
{
    private readonly CryptoAlgorithm _hashAlgo = CryptoAlgorithm.Create(AlgorithmTypes.Hash);

    public void RegisterUser(string username, string password)
    {
        // Create secret from password
        Secret secret = password.CreateSecret(_hashAlgo);

        // Store in database
        // db.Save(new User
        // {
        //     Username = username,
        //     PasswordHash = secret.Hash,
        //     PasswordSalt = secret.Salt
        // });
    }

    public bool ValidateLogin(string username, string password)
    {
        // Retrieve from database
        // var user = db.GetUser(username);
        // var storedSecret = new Secret
        // {
        //     Hash = user.PasswordHash,
        //     Salt = user.PasswordSalt
        // };

        // Validate password
        // return storedSecret.IsValid(password, _hashAlgo);

        return false; // Placeholder
    }
}

RSA Encryption

RSA is an asymmetric encryption algorithm using public/private key pairs.

GenerateRsa()

Generates a new RSA key pair.

using Ecng.Security;
using System.Security.Cryptography;

// Generate new RSA key pair (includes both public and private keys)
RSAParameters keyPair = CryptoHelper.GenerateRsa();
FromRsa(RSAParameters param) / ToRsa(byte[] key)

Converts RSA parameters to/from byte arrays for storage.

using Ecng.Security;

// Generate key pair
RSAParameters privateKey = CryptoHelper.GenerateRsa();

// Convert to bytes for storage
byte[] privateKeyBytes = privateKey.FromRsa();

// Later, restore from bytes
RSAParameters restoredKey = privateKeyBytes.ToRsa();
PublicPart(RSAParameters param)

Extracts only the public key portion from an RSA key pair.

// Generate private key (which includes public key)
RSAParameters privateKey = CryptoHelper.GenerateRsa();

// Extract public key only
RSAParameters publicKey = privateKey.PublicPart();

// Convert to bytes for sharing
byte[] publicKeyBytes = publicKey.FromRsa();
RSA Encryption/Decryption
using Ecng.Security;
using Ecng.Security.Cryptographers;
using System.Security.Cryptography;
using Ecng.Common;

// Generate key pair
RSAParameters privateKey = CryptoHelper.GenerateRsa();
RSAParameters publicKey = privateKey.PublicPart();

// Convert to bytes
byte[] publicKeyBytes = publicKey.FromRsa();
byte[] privateKeyBytes = privateKey.FromRsa();

// Encrypt with public key
using (var encryptor = new AsymmetricCryptographer(RSA.Create(), publicKeyBytes, null))
{
    byte[] plainText = "Secret message".UTF8();
    byte[] encrypted = encryptor.Encrypt(plainText);

    // Decrypt with private key
    using (var decryptor = new AsymmetricCryptographer(RSA.Create(), null, privateKeyBytes))
    {
        byte[] decrypted = decryptor.Decrypt(encrypted);
        Console.WriteLine(decrypted.UTF8()); // Outputs: "Secret message"
    }
}

Using CryptoAlgorithm:

using Ecng.Security;
using Ecng.Common;

// Generate keys
RSAParameters keyPair = CryptoHelper.GenerateRsa();
byte[] publicKey = keyPair.PublicPart().FromRsa();
byte[] privateKey = keyPair.FromRsa();

// Create algorithm instance
using (var algo = CryptoAlgorithm.Create(AlgorithmTypes.Asymmetric, publicKey, privateKey))
{
    byte[] plainText = "Sensitive data".UTF8();

    // Encrypt
    byte[] encrypted = algo.Encrypt(plainText);

    // Decrypt
    byte[] decrypted = algo.Decrypt(encrypted);

    Console.WriteLine(decrypted.UTF8()); // Outputs: "Sensitive data"
}

Digital Signatures

Digital signatures verify data authenticity and integrity.

Creating a Signature
using Ecng.Security;
using Ecng.Common;
using System.Security.Cryptography;

// Generate key pair
RSAParameters keyPair = CryptoHelper.GenerateRsa();
byte[] privateKeyBytes = keyPair.FromRsa();

// Data to sign
byte[] data = "Important document".UTF8();

// Create signature with private key
using (var algo = CryptoAlgorithm.Create(AlgorithmTypes.Asymmetric, null, privateKeyBytes))
{
    byte[] signature = algo.CreateSignature(data, () => SHA256.Create());
}
Verifying a Signature
using Ecng.Security;

// Extract public key
RSAParameters publicKey = keyPair.PublicPart();
byte[] publicKeyBytes = publicKey.FromRsa();

// Verify signature with public key
using (var verifier = CryptoAlgorithm.CreateAsymmetricVerifier(publicKeyBytes))
{
    bool isValid = verifier.VerifySignature(data, signature);

    if (isValid)
        Console.WriteLine("Signature is valid!");
    else
        Console.WriteLine("Signature is invalid!");
}

Complete Signature Example:

using Ecng.Security;
using Ecng.Common;
using System.Security.Cryptography;

// Generate key pair
RSAParameters keyPair = CryptoHelper.GenerateRsa();
byte[] publicKeyBytes = keyPair.PublicPart().FromRsa();
byte[] privateKeyBytes = keyPair.FromRsa();

// Document to sign
byte[] document = "This is an important contract.".UTF8();

// Sign the document
byte[] signature;
using (var signer = CryptoAlgorithm.Create(AlgorithmTypes.Asymmetric, null, privateKeyBytes))
{
    signature = signer.CreateSignature(document, () => SHA256.Create());
}

// Verify the signature (can be done by anyone with the public key)
using (var verifier = CryptoAlgorithm.CreateAsymmetricVerifier(publicKeyBytes))
{
    bool isAuthentic = verifier.VerifySignature(document, signature);
    Console.WriteLine($"Document is authentic: {isAuthentic}");
}

// Try to verify tampered document
byte[] tamperedDocument = "This is an modified contract.".UTF8();
using (var verifier = CryptoAlgorithm.CreateAsymmetricVerifier(publicKeyBytes))
{
    bool isAuthentic = verifier.VerifySignature(tamperedDocument, signature);
    Console.WriteLine($"Tampered document is authentic: {isAuthentic}"); // False
}

X.509 Certificates

Use X.509 certificates for encryption and signing.

X509Cryptographer

Wrapper around X.509 certificates for cryptographic operations.

using Ecng.Security.Cryptographers;
using System.Security.Cryptography.X509Certificates;
using Ecng.Common;

// Load certificate from file
X509Certificate2 cert = new X509Certificate2("mycert.pfx", "password");

// Create cryptographer
using (var cryptographer = new X509Cryptographer(cert))
{
    byte[] plainText = "Encrypted with certificate".UTF8();

    // Encrypt
    byte[] encrypted = cryptographer.Encrypt(plainText);

    // Decrypt
    byte[] decrypted = cryptographer.Decrypt(encrypted);

    Console.WriteLine(decrypted.UTF8());
}

Signing with Certificates:

using Ecng.Security.Cryptographers;
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography;
using Ecng.Common;

X509Certificate2 cert = new X509Certificate2("mycert.pfx", "password");

using (var cryptographer = new X509Cryptographer(cert))
{
    byte[] data = "Document to sign".UTF8();

    // Create signature
    byte[] signature = cryptographer.CreateSignature(data, () => SHA256.Create());

    // Verify signature
    bool isValid = cryptographer.VerifySignature(data, signature);
    Console.WriteLine($"Signature valid: {isValid}");
}

Authorization

The library includes authorization interfaces and implementations for login validation.

IAuthorization

Interface for implementing custom authorization logic.

public interface IAuthorization
{
    ValueTask<string> ValidateCredentials(
        string login,
        SecureString password,
        IPAddress clientAddress,
        CancellationToken cancellationToken);
}
AnonymousAuthorization

Allows unrestricted access (useful for testing).

using Ecng.Security;

var auth = new AnonymousAuthorization();
string sessionId = await auth.ValidateCredentials(
    "anyuser",
    null,
    IPAddress.Loopback,
    CancellationToken.None);

Console.WriteLine($"Session ID: {sessionId}"); // Always succeeds
SimpleAuthorization

Validates against a single username/password pair.

using Ecng.Security;
using System.Security;
using System.Net;

// Create secure password
var securePassword = new SecureString();
foreach (char c in "MyPassword")
    securePassword.AppendChar(c);
securePassword.MakeReadOnly();

// Setup authorization
var auth = new SimpleAuthorization
{
    Login = "admin",
    Password = securePassword
};

// Validate credentials
try
{
    string sessionId = await auth.ValidateCredentials(
        "admin",
        securePassword,
        IPAddress.Parse("192.168.1.1"),
        CancellationToken.None);

    Console.WriteLine($"Login successful! Session: {sessionId}");
}
catch (UnauthorizedAccessException)
{
    Console.WriteLine("Invalid credentials!");
}
UnauthorizedAuthorization

Denies all access (useful for disabling endpoints).

using Ecng.Security;

var auth = new UnauthorizedAuthorization();

try
{
    await auth.ValidateCredentials("user", null, null, CancellationToken.None);
}
catch (UnauthorizedAccessException)
{
    Console.WriteLine("Access denied!"); // Always throws
}

Usage Examples

Example 1: Secure File Encryption

using Ecng.Security;
using Ecng.Common;
using System.IO;

public class SecureFileManager
{
    private readonly string _password;
    private readonly byte[] _salt;

    public SecureFileManager(string password)
    {
        _password = password;
        _salt = TypeHelper.GenerateSalt(CryptoHelper.DefaultSaltSize);
    }

    public void EncryptFile(string inputPath, string outputPath)
    {
        byte[] plainText = File.ReadAllBytes(inputPath);
        byte[] iv = new byte[16];

        byte[] encrypted = plainText.EncryptAes(_password, _salt, iv);

        // Store salt and IV with the encrypted data
        using (var fs = File.Create(outputPath))
        {
            fs.Write(_salt, 0, _salt.Length);
            fs.Write(iv, 0, iv.Length);
            fs.Write(encrypted, 0, encrypted.Length);
        }
    }

    public void DecryptFile(string inputPath, string outputPath)
    {
        byte[] fileData = File.ReadAllBytes(inputPath);

        // Extract salt, IV, and encrypted data
        byte[] salt = new byte[CryptoHelper.DefaultSaltSize];
        byte[] iv = new byte[16];
        byte[] encrypted = new byte[fileData.Length - salt.Length - iv.Length];

        Buffer.BlockCopy(fileData, 0, salt, 0, salt.Length);
        Buffer.BlockCopy(fileData, salt.Length, iv, 0, iv.Length);
        Buffer.BlockCopy(fileData, salt.Length + iv.Length, encrypted, 0, encrypted.Length);

        // Decrypt
        byte[] decrypted = encrypted.DecryptAes(_password, salt, iv);
        File.WriteAllBytes(outputPath, decrypted);
    }
}

Example 2: API Request Signing

using Ecng.Security;
using Ecng.Common;
using System.Security.Cryptography;

public class ApiClient
{
    private readonly RSAParameters _privateKey;
    private readonly byte[] _publicKeyBytes;

    public ApiClient()
    {
        // Generate or load keys
        _privateKey = CryptoHelper.GenerateRsa();
        _publicKeyBytes = _privateKey.PublicPart().FromRsa();
    }

    public (byte[] data, byte[] signature) SignRequest(string requestBody)
    {
        byte[] data = requestBody.UTF8();

        using (var signer = CryptoAlgorithm.Create(
            AlgorithmTypes.Asymmetric,
            null,
            _privateKey.FromRsa()))
        {
            byte[] signature = signer.CreateSignature(data, () => SHA256.Create());
            return (data, signature);
        }
    }

    public byte[] GetPublicKey() => _publicKeyBytes;
}

public class ApiServer
{
    public bool VerifyRequest(byte[] data, byte[] signature, byte[] clientPublicKey)
    {
        using (var verifier = CryptoAlgorithm.CreateAsymmetricVerifier(clientPublicKey))
        {
            return verifier.VerifySignature(data, signature);
        }
    }
}

Example 3: User Authentication System

using Ecng.Security;
using System;
using System.Collections.Generic;

public class User
{
    public string Username { get; set; }
    public Secret PasswordSecret { get; set; }
}

public class AuthenticationService
{
    private readonly Dictionary<string, User> _users = new();
    private readonly CryptoAlgorithm _hashAlgo;

    public AuthenticationService()
    {
        _hashAlgo = CryptoAlgorithm.Create(AlgorithmTypes.Hash);
    }

    public void RegisterUser(string username, string password)
    {
        if (_users.ContainsKey(username))
            throw new InvalidOperationException("User already exists");

        var user = new User
        {
            Username = username,
            PasswordSecret = password.CreateSecret(_hashAlgo)
        };

        _users[username] = user;
        Console.WriteLine($"User '{username}' registered successfully");
    }

    public bool Login(string username, string password)
    {
        if (!_users.TryGetValue(username, out var user))
        {
            Console.WriteLine("User not found");
            return false;
        }

        bool isValid = user.PasswordSecret.IsValid(password, _hashAlgo);

        if (isValid)
            Console.WriteLine($"User '{username}' logged in successfully");
        else
            Console.WriteLine("Invalid password");

        return isValid;
    }
}

// Usage
var authService = new AuthenticationService();
authService.RegisterUser("alice", "SecurePass123!");
authService.RegisterUser("bob", "AnotherPass456@");

authService.Login("alice", "SecurePass123!");  // Success
authService.Login("alice", "WrongPassword");    // Failure

Example 4: Data Integrity Verification

using Ecng.Security;
using Ecng.Common;

public class DataIntegrityChecker
{
    public string ComputeChecksum(byte[] data, string algorithm = "sha256")
    {
        return algorithm.ToLowerInvariant() switch
        {
            "md5" => data.Md5(),
            "sha256" => data.Sha256(),
            "sha512" => data.Sha512(),
            _ => throw new ArgumentException("Unsupported algorithm")
        };
    }

    public bool VerifyChecksum(byte[] data, string expectedChecksum, string algorithm = "sha256")
    {
        string actualChecksum = ComputeChecksum(data, algorithm);
        return actualChecksum.Equals(expectedChecksum, StringComparison.OrdinalIgnoreCase);
    }
}

// Usage
var checker = new DataIntegrityChecker();
byte[] originalData = "Important data".UTF8();

// Compute checksum
string checksum = checker.ComputeChecksum(originalData, "sha256");
Console.WriteLine($"Checksum: {checksum}");

// Verify data hasn't been modified
bool isValid = checker.VerifyChecksum(originalData, checksum, "sha256");
Console.WriteLine($"Data is valid: {isValid}"); // True

// Verify modified data
byte[] modifiedData = "Modified data".UTF8();
bool isModified = checker.VerifyChecksum(modifiedData, checksum, "sha256");
Console.WriteLine($"Modified data is valid: {isModified}"); // False

Best Practices

Security Recommendations

  1. Password Storage

    • Always use Secret with salted hashing for password storage
    • Never store passwords in plain text
    • Use SecureString when handling passwords in memory
  2. Salt Generation

    • Use TypeHelper.GenerateSalt() to generate cryptographically secure random salts
    • Recommended salt size: 128 bytes (CryptoHelper.DefaultSaltSize)
    • Never reuse salts across different passwords
  3. AES Encryption

    • Always generate a new random salt for each encryption operation
    • Store the salt and IV alongside the encrypted data
    • Use strong passwords/passphrases for key derivation
    • Consider using RSA for encrypting the AES key itself (hybrid encryption)
  4. RSA Key Management

    • Keep private keys secure and never expose them
    • Use at least 2048-bit RSA keys (default in modern .NET)
    • Share only the public key for encryption and signature verification
    • Store private keys encrypted when persisting to disk
  5. Digital Signatures

    • Use SHA256 or stronger hash algorithms for signatures
    • Verify signatures before processing signed data
    • Sign data before encryption for non-repudiation
  6. Hashing

    • For password hashing, use Secret class, not direct hash functions
    • For data integrity, SHA256 or SHA512 are recommended
    • MD5 is provided for compatibility but should be avoided for security-critical applications

Performance Tips

  1. Dispose Cryptographic Objects

    • Always dispose CryptoAlgorithm instances (use using statements)
    • This ensures keys are properly cleared from memory
  2. Reuse Algorithm Instances

    • When performing multiple operations, reuse the same CryptoAlgorithm instance
    • Create once and dispose when all operations are complete
  3. Async Operations

    • The IAuthorization interface is async-friendly
    • Use async/await for authorization operations in web applications
  4. Memory Management

    • Use SymmetricCryptographer.ZeroOutBytes() to clear sensitive data from memory
    • Be mindful of byte array allocations when processing large files

Common Pitfalls to Avoid

  1. Don't hardcode passwords or keys in source code
  2. Don't use the same IV for multiple AES encryption operations
  3. Don't forget to store salt and IV when encrypting data
  4. Don't confuse public and private keys in RSA operations
  5. Don't skip signature verification when receiving signed data
  6. Don't use MD5 for security-critical applications
  7. Don't share private keys or expose them in logs/error messages

License

This library is part of the Ecng toolkit. Please refer to the main repository for licensing information.

Support

For issues, questions, or contributions, please visit the main Ecng repository.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  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 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  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 (1)

Showing the top 1 NuGet packages that depend on Ecng.Security:

Package Downloads
Ecng.Serialization

Ecng system framework

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.269 208 12/22/2025
1.0.268 292 12/21/2025
1.0.267 452 12/19/2025
1.0.266 440 12/19/2025
1.0.265 740 12/17/2025
1.0.264 922 12/15/2025
1.0.263 681 12/15/2025
1.0.262 641 12/14/2025
1.0.261 1,750 12/12/2025
1.0.260 923 12/12/2025
1.0.259 531 12/12/2025
1.0.258 530 12/12/2025
1.0.257 907 12/12/2025
1.0.256 1,235 12/2/2025
1.0.255 1,123 12/2/2025
1.0.254 1,118 12/2/2025
1.0.253 727 11/30/2025
1.0.252 575 11/29/2025
1.0.251 580 11/28/2025
1.0.250 579 11/28/2025
1.0.249 646 11/27/2025
1.0.248 704 11/24/2025
1.0.247 645 11/24/2025
1.0.246 635 11/23/2025
1.0.245 1,164 11/22/2025
1.0.244 1,409 11/20/2025
1.0.243 886 11/18/2025
1.0.242 832 11/18/2025
1.0.241 860 11/13/2025
1.0.240 761 11/10/2025
1.0.239 1,607 11/1/2025
1.0.238 827 10/28/2025
1.0.237 801 10/27/2025
1.0.236 669 10/27/2025
1.0.235 614 10/25/2025
1.0.234 4,229 10/3/2025
1.0.233 2,021 9/28/2025
1.0.232 759 9/25/2025
1.0.231 5,164 9/2/2025
1.0.230 3,159 8/30/2025
1.0.229 815 8/30/2025
1.0.228 1,643 8/19/2025
1.0.227 7,571 7/13/2025
1.0.226 631 7/13/2025
1.0.225 632 7/12/2025
1.0.224 1,877 7/8/2025
1.0.223 1,353 7/4/2025
1.0.222 685 7/2/2025
1.0.221 5,448 6/16/2025
1.0.220 823 6/9/2025
1.0.219 686 6/8/2025
1.0.218 2,310 5/21/2025
1.0.217 841 5/17/2025
1.0.216 2,350 5/12/2025
1.0.215 744 5/12/2025
1.0.214 2,994 4/17/2025
1.0.213 5,693 3/22/2025
1.0.212 713 3/20/2025
1.0.211 645 3/20/2025
1.0.210 676 3/19/2025
1.0.209 5,668 2/26/2025
1.0.208 735 2/26/2025
1.0.207 9,208 2/5/2025
1.0.206 4,574 1/21/2025
1.0.205 3,633 1/14/2025
1.0.204 2,537 1/12/2025
1.0.203 1,262 1/10/2025
1.0.202 4,771 12/27/2024
1.0.201 1,626 11/20/2024
1.0.200 4,118 11/18/2024
1.0.199 2,482 11/7/2024
1.0.198 1,816 10/19/2024
1.0.197 3,766 10/12/2024
1.0.196 4,330 10/5/2024
1.0.195 5,401 9/18/2024
1.0.194 710 9/17/2024
1.0.193 5,007 9/3/2024
1.0.192 733 9/1/2024
1.0.191 14,645 6/12/2024
1.0.190 3,536 5/28/2024
1.0.189 4,301 5/4/2024
1.0.188 2,943 4/23/2024
1.0.187 2,057 4/21/2024
1.0.186 904 4/14/2024
1.0.185 6,195 3/28/2024
1.0.184 850 3/17/2024
1.0.183 4,152 2/23/2024
1.0.182 724 2/23/2024
1.0.181 4,081 2/18/2024
1.0.180 754 2/18/2024
1.0.179 797 2/16/2024
1.0.178 2,827 2/13/2024
1.0.177 2,618 2/8/2024
1.0.176 3,038 2/5/2024
1.0.175 706 2/4/2024
1.0.174 3,164 1/23/2024
1.0.173 753 1/23/2024
1.0.172 2,447 1/12/2024
1.0.171 5,868 1/2/2024
1.0.170 909 12/29/2023
1.0.169 18,913 11/12/2023
1.0.168 1,257 11/10/2023
1.0.167 831 11/10/2023
1.0.166 1,077 11/9/2023
1.0.165 1,863 11/3/2023
1.0.164 809 11/1/2023
1.0.163 913 11/1/2023
1.0.162 26,211 9/8/2023
1.0.161 1,202 9/8/2023
1.0.160 1,404 9/3/2023
1.0.159 1,688 8/21/2023
1.0.158 1,906 8/14/2023
1.0.157 2,062 8/10/2023
1.0.156 41,753 6/29/2023
1.0.155 16,249 5/27/2023
1.0.154 1,368 5/21/2023
1.0.153 1,532 5/19/2023
1.0.152 26,924 5/8/2023
1.0.151 5,884 4/22/2023
1.0.150 1,344 4/21/2023
1.0.149 52,484 4/3/2023
1.0.148 8,386 3/13/2023
1.0.147 20,393 3/6/2023
1.0.146 2,525 2/26/2023
1.0.145 17,215 2/21/2023
1.0.144 1,590 2/20/2023
1.0.143 2,990 2/15/2023
1.0.142 1,608 2/14/2023
1.0.141 34,268 2/9/2023
1.0.140 18,111 2/7/2023
1.0.139 2,206 2/4/2023
1.0.138 22,593 2/2/2023
1.0.137 18,681 1/30/2023
1.0.136 7,498 1/18/2023
1.0.135 46,319 12/30/2022
1.0.134 3,615 12/23/2022
1.0.133 23,000 12/12/2022
1.0.132 25,580 12/4/2022
1.0.131 2,583 12/4/2022
1.0.130 3,326 11/30/2022
1.0.129 2,590 11/29/2022
1.0.128 2,674 11/28/2022
1.0.127 6,937 11/18/2022
1.0.126 29,791 11/11/2022
1.0.125 2,616 11/11/2022
1.0.124 2,603 11/10/2022
1.0.123 2,826 11/5/2022
1.0.122 4,119 11/4/2022
1.0.121 26,715 11/1/2022
1.0.120 27,150 10/16/2022
1.0.119 10,005 9/10/2022
1.0.118 54,224 9/8/2022
1.0.117 3,132 9/8/2022
1.0.116 3,097 9/8/2022
1.0.115 5,459 9/4/2022
1.0.114 94,228 8/24/2022
1.0.113 12,740 8/8/2022
1.0.112 6,503 7/26/2022
1.0.111 3,633 7/26/2022
1.0.110 57,087 7/19/2022
1.0.109 49,066 7/18/2022
1.0.108 8,826 7/8/2022
1.0.107 7,822 6/18/2022
1.0.106 3,569 6/6/2022
1.0.105 101,172 4/30/2022
1.0.104 3,866 4/20/2022
1.0.103 3,947 4/10/2022
1.0.102 3,869 4/7/2022
1.0.101 3,904 4/7/2022
1.0.100 3,976 4/2/2022
1.0.99 15,265 3/29/2022
1.0.98 6,775 3/27/2022
1.0.97 293,922 1/24/2022
1.0.96 166,053 12/29/2021
1.0.95 31,313 12/20/2021
1.0.94 4,113 12/13/2021
1.0.93 31,797 12/7/2021
1.0.92 30,559 12/6/2021
1.0.91 5,697 12/2/2021
1.0.90 32,327 11/29/2021
1.0.89 31,091 11/22/2021
1.0.88 2,423 11/17/2021
1.0.87 32,880 11/13/2021
1.0.86 5,835 11/10/2021
1.0.85 2,584 11/9/2021
1.0.84 65,714 11/5/2021
1.0.83 4,211 11/4/2021
1.0.82 2,458 11/4/2021
1.0.81 2,385 11/3/2021
1.0.80 2,608 10/30/2021
1.0.79 34,094 10/21/2021
1.0.78 3,039 10/17/2021
1.0.77 64,238 10/14/2021
1.0.76 13,823 10/13/2021
1.0.75 2,591 10/12/2021
1.0.74 34,392 10/11/2021
1.0.73 2,458 10/9/2021
1.0.72 37,660 10/7/2021
1.0.71 39,700 10/7/2021
1.0.70 2,522 10/7/2021
1.0.69 2,504 10/6/2021
1.0.68 2,532 9/28/2021
1.0.67 36,362 9/23/2021
1.0.66 4,122 9/10/2021
1.0.65 2,265 9/9/2021
1.0.64 2,187 9/8/2021
1.0.63 2,226 9/8/2021
1.0.62 33,258 9/6/2021
1.0.61 2,424 8/31/2021
1.0.60 618 8/30/2021
1.0.59 32,029 7/31/2021
1.0.58 56,717 7/30/2021
1.0.57 1,356 7/26/2021
1.0.56 84,336 7/5/2021
1.0.55 1,330 7/1/2021
1.0.54 59,405 6/4/2021
1.0.53 85,438 4/26/2021
1.0.52 30,010 4/19/2021
1.0.51 139,998 4/7/2021
1.0.50 29,229 4/3/2021
1.0.49 167,000 3/22/2021
1.0.48 104,707 3/4/2021
1.0.47 30,906 2/26/2021
1.0.46 155,420 2/2/2021
1.0.45 53,835 1/26/2021
1.0.44 52,921 1/24/2021
1.0.43 1,240 1/24/2021
1.0.42 1,394 1/23/2021
1.0.41 54,150 1/20/2021
1.0.40 1,337 1/20/2021
1.0.39 27,853 1/18/2021
1.0.38 1,351 1/18/2021
1.0.37 26,870 1/16/2021
1.0.36 109,093 12/16/2020
1.0.35 54,093 12/14/2020
1.0.34 31,644 12/9/2020
1.0.33 2,159 12/6/2020
1.0.32 1,465 12/2/2020
1.0.31 1,367 12/2/2020
1.0.30 29,345 12/1/2020
1.0.29 154,228 11/12/2020
1.0.29-atestpub 813 11/11/2020
1.0.28 28,911 10/11/2020
1.0.27 105,434 9/9/2020
1.0.26 27,448 9/3/2020
1.0.25 28,006 8/20/2020
1.0.24 79,514 8/9/2020
1.0.23 27,245 7/28/2020
1.0.22 27,204 7/19/2020
1.0.21 52,305 7/6/2020
1.0.20 80,212 6/6/2020
1.0.19 28,446 6/4/2020
1.0.18 54,053 5/29/2020
1.0.17 54,112 5/21/2020
1.0.16 1,591 5/17/2020
1.0.15 51,686 5/12/2020
1.0.14 102,055 5/4/2020
1.0.13 4,458 4/24/2020
1.0.12 6,063 4/22/2020
1.0.11 1,448 4/22/2020
1.0.10 1,509 4/21/2020
1.0.9 28,439 4/18/2020
1.0.8 26,656 4/16/2020
1.0.7 1,428 4/16/2020
1.0.6 22,725 4/15/2020
1.0.5 24,513 4/11/2020
1.0.4 24,231 4/3/2020
1.0.3 1,369 4/1/2020
1.0.2 11,472 3/27/2020
1.0.1 10,432 3/22/2020
1.0.0 3,225 3/22/2020