Ecng.Security 1.0.272

There is a newer version of this package available.
See the version list below for details.
dotnet add package Ecng.Security --version 1.0.272
                    
NuGet\Install-Package Ecng.Security -Version 1.0.272
                    
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.272" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Ecng.Security" Version="1.0.272" />
                    
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.272
                    
#r "nuget: Ecng.Security, 1.0.272"
                    
#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.272
                    
#: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.272
                    
Install as a Cake Addin
#tool nuget:?package=Ecng.Security&version=1.0.272
                    
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.275 0 12/26/2025
1.0.274 0 12/26/2025
1.0.273 0 12/26/2025
1.0.272 26 12/26/2025
1.0.271 115 12/25/2025
1.0.270 133 12/25/2025
1.0.269 742 12/22/2025
1.0.268 634 12/21/2025
1.0.267 670 12/19/2025
1.0.266 665 12/19/2025
1.0.265 858 12/17/2025
1.0.264 923 12/15/2025
1.0.263 682 12/15/2025
1.0.262 642 12/14/2025
1.0.261 1,752 12/12/2025
1.0.260 925 12/12/2025
1.0.259 534 12/12/2025
1.0.258 533 12/12/2025
1.0.257 911 12/12/2025
1.0.256 1,243 12/2/2025
1.0.255 1,125 12/2/2025
1.0.254 1,120 12/2/2025
1.0.253 729 11/30/2025
1.0.252 578 11/29/2025
1.0.251 583 11/28/2025
1.0.250 581 11/28/2025
1.0.249 649 11/27/2025
1.0.248 706 11/24/2025
1.0.247 648 11/24/2025
1.0.246 637 11/23/2025
1.0.245 1,164 11/22/2025
1.0.244 1,413 11/20/2025
1.0.243 886 11/18/2025
1.0.242 834 11/18/2025
1.0.241 863 11/13/2025
1.0.240 761 11/10/2025
1.0.239 1,608 11/1/2025
1.0.238 827 10/28/2025
1.0.237 815 10/27/2025
1.0.236 672 10/27/2025
1.0.235 615 10/25/2025
1.0.234 4,235 10/3/2025
1.0.233 2,023 9/28/2025
1.0.232 760 9/25/2025
1.0.231 5,181 9/2/2025
1.0.230 3,162 8/30/2025
1.0.229 817 8/30/2025
1.0.228 1,645 8/19/2025
1.0.227 7,582 7/13/2025
1.0.226 632 7/13/2025
1.0.225 633 7/12/2025
1.0.224 1,878 7/8/2025
1.0.223 1,355 7/4/2025
1.0.222 686 7/2/2025
1.0.221 5,454 6/16/2025
1.0.220 830 6/9/2025
1.0.219 687 6/8/2025
1.0.218 2,312 5/21/2025
1.0.217 842 5/17/2025
1.0.216 2,352 5/12/2025
1.0.215 745 5/12/2025
1.0.214 2,995 4/17/2025
1.0.213 5,695 3/22/2025
1.0.212 714 3/20/2025
1.0.211 647 3/20/2025
1.0.210 676 3/19/2025
1.0.209 5,670 2/26/2025
1.0.208 735 2/26/2025
1.0.207 9,208 2/5/2025
1.0.206 4,576 1/21/2025
1.0.205 3,633 1/14/2025
1.0.204 2,538 1/12/2025
1.0.203 1,264 1/10/2025
1.0.202 4,774 12/27/2024
1.0.201 1,628 11/20/2024
1.0.200 4,119 11/18/2024
1.0.199 2,483 11/7/2024
1.0.198 1,817 10/19/2024
1.0.197 3,768 10/12/2024
1.0.196 4,331 10/5/2024
1.0.195 5,402 9/18/2024
1.0.194 710 9/17/2024
1.0.193 5,008 9/3/2024
1.0.192 733 9/1/2024
1.0.191 14,647 6/12/2024
1.0.190 3,536 5/28/2024
1.0.189 4,302 5/4/2024
1.0.188 2,943 4/23/2024
1.0.187 2,058 4/21/2024
1.0.186 905 4/14/2024
1.0.185 6,197 3/28/2024
1.0.184 851 3/17/2024
1.0.183 4,155 2/23/2024
1.0.182 725 2/23/2024
1.0.181 4,082 2/18/2024
1.0.180 755 2/18/2024
1.0.179 797 2/16/2024
1.0.178 2,828 2/13/2024
1.0.177 2,620 2/8/2024
1.0.176 3,038 2/5/2024
1.0.175 707 2/4/2024
1.0.174 3,164 1/23/2024
1.0.173 755 1/23/2024
1.0.172 2,448 1/12/2024
1.0.171 5,869 1/2/2024
1.0.170 910 12/29/2023
1.0.169 18,914 11/12/2023
1.0.168 1,258 11/10/2023
1.0.167 832 11/10/2023
1.0.166 1,077 11/9/2023
1.0.165 1,863 11/3/2023
1.0.164 811 11/1/2023
1.0.163 914 11/1/2023
1.0.162 26,211 9/8/2023
1.0.161 1,203 9/8/2023
1.0.160 1,406 9/3/2023
1.0.159 1,691 8/21/2023
1.0.158 1,908 8/14/2023
1.0.157 2,063 8/10/2023
1.0.156 41,754 6/29/2023
1.0.155 16,250 5/27/2023
1.0.154 1,370 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,345 4/21/2023
1.0.149 52,485 4/3/2023
1.0.148 8,387 3/13/2023
1.0.147 20,394 3/6/2023
1.0.146 2,525 2/26/2023
1.0.145 17,222 2/21/2023
1.0.144 1,591 2/20/2023
1.0.143 2,990 2/15/2023
1.0.142 1,609 2/14/2023
1.0.141 34,270 2/9/2023
1.0.140 18,112 2/7/2023
1.0.139 2,208 2/4/2023
1.0.138 22,594 2/2/2023
1.0.137 18,683 1/30/2023
1.0.136 7,500 1/18/2023
1.0.135 46,330 12/30/2022
1.0.134 3,618 12/23/2022
1.0.133 23,001 12/12/2022
1.0.132 25,582 12/4/2022
1.0.131 2,584 12/4/2022
1.0.130 3,330 11/30/2022
1.0.129 2,594 11/29/2022
1.0.128 2,675 11/28/2022
1.0.127 6,938 11/18/2022
1.0.126 29,794 11/11/2022
1.0.125 2,618 11/11/2022
1.0.124 2,605 11/10/2022
1.0.123 2,828 11/5/2022
1.0.122 4,122 11/4/2022
1.0.121 26,717 11/1/2022
1.0.120 27,151 10/16/2022
1.0.119 10,008 9/10/2022
1.0.118 54,226 9/8/2022
1.0.117 3,135 9/8/2022
1.0.116 3,099 9/8/2022
1.0.115 5,462 9/4/2022
1.0.114 94,230 8/24/2022
1.0.113 12,743 8/8/2022
1.0.112 6,506 7/26/2022
1.0.111 3,634 7/26/2022
1.0.110 57,088 7/19/2022
1.0.109 49,067 7/18/2022
1.0.108 8,829 7/8/2022
1.0.107 7,825 6/18/2022
1.0.106 3,572 6/6/2022
1.0.105 101,173 4/30/2022
1.0.104 3,867 4/20/2022
1.0.103 3,948 4/10/2022
1.0.102 3,872 4/7/2022
1.0.101 3,907 4/7/2022
1.0.100 3,979 4/2/2022
1.0.99 15,267 3/29/2022
1.0.98 6,777 3/27/2022
1.0.97 293,926 1/24/2022
1.0.96 166,055 12/29/2021
1.0.95 31,315 12/20/2021
1.0.94 4,114 12/13/2021
1.0.93 31,799 12/7/2021
1.0.92 30,561 12/6/2021
1.0.91 5,699 12/2/2021
1.0.90 32,329 11/29/2021
1.0.89 31,095 11/22/2021
1.0.88 2,424 11/17/2021
1.0.87 32,882 11/13/2021
1.0.86 5,837 11/10/2021
1.0.85 2,585 11/9/2021
1.0.84 65,716 11/5/2021
1.0.83 4,213 11/4/2021
1.0.82 2,460 11/4/2021
1.0.81 2,387 11/3/2021
1.0.80 2,609 10/30/2021
1.0.79 34,097 10/21/2021
1.0.78 3,042 10/17/2021
1.0.77 64,241 10/14/2021
1.0.76 13,825 10/13/2021
1.0.75 2,592 10/12/2021
1.0.74 34,394 10/11/2021
1.0.73 2,460 10/9/2021
1.0.72 37,662 10/7/2021
1.0.71 39,703 10/7/2021
1.0.70 2,525 10/7/2021
1.0.69 2,506 10/6/2021
1.0.68 2,534 9/28/2021
1.0.67 36,363 9/23/2021
1.0.66 4,125 9/10/2021
1.0.65 2,266 9/9/2021
1.0.64 2,188 9/8/2021
1.0.63 2,228 9/8/2021
1.0.62 33,262 9/6/2021
1.0.61 2,427 8/31/2021
1.0.60 621 8/30/2021
1.0.59 32,031 7/31/2021
1.0.58 56,719 7/30/2021
1.0.57 1,359 7/26/2021
1.0.56 84,337 7/5/2021
1.0.55 1,333 7/1/2021
1.0.54 59,408 6/4/2021
1.0.53 85,440 4/26/2021
1.0.52 30,011 4/19/2021
1.0.51 140,009 4/7/2021
1.0.50 29,231 4/3/2021
1.0.49 167,002 3/22/2021
1.0.48 104,708 3/4/2021
1.0.47 30,909 2/26/2021
1.0.46 155,423 2/2/2021
1.0.45 53,838 1/26/2021
1.0.44 52,923 1/24/2021
1.0.43 1,243 1/24/2021
1.0.42 1,396 1/23/2021
1.0.41 54,154 1/20/2021
1.0.40 1,340 1/20/2021
1.0.39 27,857 1/18/2021
1.0.38 1,354 1/18/2021
1.0.37 26,873 1/16/2021
1.0.36 109,096 12/16/2020
1.0.35 54,096 12/14/2020
1.0.34 31,646 12/9/2020
1.0.33 2,162 12/6/2020
1.0.32 1,467 12/2/2020
1.0.31 1,370 12/2/2020
1.0.30 29,348 12/1/2020
1.0.29 154,231 11/12/2020
1.0.29-atestpub 816 11/11/2020
1.0.28 28,914 10/11/2020
1.0.27 105,437 9/9/2020
1.0.26 27,451 9/3/2020
1.0.25 28,009 8/20/2020
1.0.24 79,516 8/9/2020
1.0.23 27,247 7/28/2020
1.0.22 27,208 7/19/2020
1.0.21 52,307 7/6/2020
1.0.20 80,214 6/6/2020
1.0.19 28,448 6/4/2020
1.0.18 54,056 5/29/2020
1.0.17 54,116 5/21/2020
1.0.16 1,594 5/17/2020
1.0.15 51,689 5/12/2020
1.0.14 102,058 5/4/2020
1.0.13 4,462 4/24/2020
1.0.12 6,065 4/22/2020
1.0.11 1,451 4/22/2020
1.0.10 1,513 4/21/2020
1.0.9 28,442 4/18/2020
1.0.8 26,660 4/16/2020
1.0.7 1,432 4/16/2020
1.0.6 22,728 4/15/2020
1.0.5 24,516 4/11/2020
1.0.4 24,234 4/3/2020
1.0.3 1,373 4/1/2020
1.0.2 11,474 3/27/2020
1.0.1 10,435 3/22/2020
1.0.0 3,227 3/22/2020