Plugin.Toolkit.Security 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Plugin.Toolkit.Security --version 1.0.0                
NuGet\Install-Package Plugin.Toolkit.Security -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="Plugin.Toolkit.Security" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Plugin.Toolkit.Security --version 1.0.0                
#r "nuget: Plugin.Toolkit.Security, 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.
// Install Plugin.Toolkit.Security as a Cake Addin
#addin nuget:?package=Plugin.Toolkit.Security&version=1.0.0

// Install Plugin.Toolkit.Security as a Cake Tool
#tool nuget:?package=Plugin.Toolkit.Security&version=1.0.0                

Plugin.Toolkit.Security

icon

NuGet .NET License: MIT

Secure Your Data, Elevate Your Trust: Plugin.Toolkit.Security 🚀

The Plugin.Toolkit.Security library provides essential security functionalities for C# applications, including working with JSON Web Tokens (JWT), generating MD5 hashes, and performing SHA-256 encryption and decryption.

🚀 Features

  • JWT Operations: Create, verify, and extract claims from JWT tokens.
  • MD5 Hashing: Generate MD5 hashes for strings.
  • SHA-256 Encryption/Decryption: Encrypt and decrypt strings using SHA-256.

📦 Installation

To install the Plugin.Toolkit.Security library, use the NuGet package manager:

dotnet add package Plugin.Toolkit.Security

💡 Usage

JWT

Parameters

  • secret: The secret key used for signing the JWT.
  • algorithm: The security algorithm to use (e.g., HmacSha256).
  • issuer: The issuer of the token (default is an empty string).
  • audience: The audience of the token (default is an empty string).

Create

Generates a JWT with specified claims.

string secret = "secret-key";
var security = new SecurityToolkit(secret, SecurityAlgorithm.HmacSha512);
Claim[] claims = new Claim[]
{
    new Claim(JwtRegisteredClaimNames.Sub, UserId)
};
string jwtString = security.JWT.Create(claims);

Verify

Verifies the validity of a given JWT.

string secret = "secret-key";
var security = new SecurityToolkit(secret, SecurityAlgorithm.HmacSha512);
bool verify = security.JWT.Verify(jwtString);
if (verify)
{
    Console.WriteLine("Token is valid.");
}
else
{
    Console.WriteLine("Token is invalid.");
}

Claims

Extracts the claims from a given JWT.

string secret = "secret-key";
var security = new SecurityToolkit(secret, SecurityAlgorithm.HmacSha512);
ClaimsPrincipal claims = security.JWT.Claims(jwtString);
if (claims != null)
{
    Console.WriteLine("Token is valid.");
    var subClaim = claims.FindFirst(JwtRegisteredClaimNames.Sub)?.Value;
    if (subClaim != null)
    {
        Console.WriteLine($"Sub: {subClaim}");
    }
}
else
{
    Console.WriteLine("Token is invalid.");
}

MD5

Hash

Generates an MD5 hash from a given input.

var security = new SecurityToolkit("");
string hash = security.MD5.Hash();

SHA256

Encryption

Encrypts a given input using SHA-256.

string secret = "secret-key";
var security = new SecurityToolkit(secret);
string strToEncrypt = "eating some cake!";
string encryptedStr = security.SHA256.Encryption(strToEncrypt);

Decryption

Decrypts a given SHA-256 encrypted input.

string secret = "secret-key";
var security = new SecurityToolkit(secret);
string encryptedStr = "xxxxxxxx";
string decryptedStr = security.SHA256.Decryption(encryptedStr);

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

Contact

If you have any questions or suggestions, please feel free to contact me at andyapin@gmail.com

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. 
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.1 72 1/26/2025
1.0.0 61 1/26/2025