Boost Your .NET Projects with Spargine: Unleashing the Power of EncryptionHelper

Spargine is a collection of open-source assemblies and NuGet packages designed for .NET 10, which I have been developing and maintaining since the release of .NET Framework 2. These assemblies are not only a core part of my projects but are also actively deployed in production environments across several companies I collaborate with.

Get Spargine

You can access the source code and NuGet packages here:

Handling sensitive data securely is a non-negotiable requirement for modern .NET applications. Whether you’re protecting credentials, encrypting configuration values, or securing data in transit or at rest, you need cryptography that is both reliable and efficient.

The EncryptionHelper class in the DotNetTips.Spargine.Core assembly delivers exactly that. It provides a high-performance, developer-friendly API for encryption, decryption, key generation, and password verification—built on proven cryptographic standards and optimized for real-world use.

Why Use EncryptionHelper?

Implementing cryptography correctly is notoriously error-prone. EncryptionHelper removes much of that complexity by offering:

  • Strong, modern encryption algorithms
  • Secure key and initialization vector (IV) generation
  • Support for authenticated encryption
  • Simple, reusable APIs
  • Performance-focused implementations suitable for production workloads

This makes it ideal for applications that need secure data handling without reinventing cryptographic plumbing.

Available Methods

The EncryptionHelper class provides a comprehensive set of utility methods for common encryption and hashing scenarios.

AES Encryption and Decryption

  • AesDecrypt(string cipherText, byte[] key, byte[] iv)
    Decrypts a string using AES encryption with a provided key and initialization vector (IV).
  • AesEncrypt(string plainText, byte[] key, byte[] iv)
    Encrypts a string using AES encryption with a provided key and initialization vector (IV).
    Example output: “RTFsqnJZU9ohNMAcGm15cA==”

AES-GCM Authenticated Encryption

  • AesGcmDecrypt(string base64Payload, byte[] key, ReadOnlySpan<byte> aad)
    Decrypts AES-GCM encrypted data and validates its integrity before returning the plaintext.
  • AesGcmEncrypt(string plainText, byte[] key, ReadOnlySpan<byte> aad)
    Encrypts text using AES-GCM (Galois/Counter Mode), providing both confidentiality and integrity through authenticated encryption.
    Example output:
    “Afn4EipQu5SZFtP4v1x5vri9W51TLQ/GUGhe0cHs+6KarGm/x4WSTUl2w20=”

Key and IV Generation

  • GenerateAesGcmKey()
    Generates a new random 256-bit (32-byte) key specifically for AES-GCM encryption.
  • GenerateAesIV()
    Generates a secure AES initialization vector (IV).
  • GenerateAesKey()
    Generates a new AES encryption key.
  • GenerateRandomKey()
    Creates a random key using a GUID-based approach for lightweight unique key generation.
    Example output: “CKT9YZWV04VR0Y7PTGE3703148”

SHA256-Based Utilities

  • SimpleSHA256Decrypt(string cipherText, string key)
    Decrypts data encrypted with SimpleSHA256Encrypt() using the same string-based key.
  • SimpleSHA256Encrypt(string plainText, string key)
    Encrypts text using a combination of SHA256 hashing and AES encryption, with the key provided as a string.
    Example output: “ybnRH+uat1ss5QvVYJ4d2Q==”
  • VerifySHA256HashedPassword(string hashedPassword, string password)
    Verifies a password by comparing it to a stored SHA256 hash, making it suitable for authentication scenarios.

When Should You Use EncryptionHelper?

EncryptionHelper is a strong fit when you need to:

  • Maintain high performance in security-critical code paths
  • Secure application secrets or configuration values
  • Encrypt sensitive user data
  • Implement password hashing and verification
  • Use modern authenticated encryption (AES-GCM)
  • Avoid common cryptography mistakes
  • Maintain high performance in security-critical code paths

Summary

The EncryptionHelper class in Spargine provides a powerful, performance-optimized toolkit for securing data in .NET applications. By combining modern encryption standards like AES and AES-GCM with easy-to-use APIs and secure key generation, it removes much of the risk and complexity traditionally associated with cryptography.

If your application handles sensitive information—and most do—EncryptionHelper gives you a safe, efficient, and developer-friendly way to protect it without sacrificing performance or maintainability.

Get Involved!

The success of open-source projects like Spargine relies on community contributions. If you find these updates useful or have ideas for further improvements, I encourage you to contribute by:

  • Submitting pull requests
  • Reporting issues
  • Suggesting new features

Your input is invaluable in making Spargine an even more powerful tool for the .NET community.

If you are interested in contributing or have any questions, feel free to contact me via email at dotnetdave@live.com. Your support and collaboration are greatly appreciated!

Thank you, and happy coding!

Pick up any books by David McCarter by going to Amazon.com: http://bit.ly/RockYourCodeBooks

One-Time
Monthly
Yearly

Make a one-time donation

Make a monthly donation

Make a yearly donation

Choose an amount

$5.00
$15.00
$100.00
$5.00
$15.00
$100.00
$5.00
$15.00
$100.00

Or enter a custom amount

$

Your contribution is appreciated.

Your contribution is appreciated.

Your contribution is appreciated.

DonateDonate monthlyDonate yearly

If you liked this article, please buy David a cup of Coffee by going here: https://www.buymeacoffee.com/dotnetdave

© The information in this article is copywritten and cannot be preproduced in any way without express permission from David McCarter.


Discover more from dotNetTips.com

Subscribe to get the latest posts sent to your email.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.