Plugin.Toolkit.Security
1.0.1
dotnet add package Plugin.Toolkit.Security --version 1.0.1
NuGet\Install-Package Plugin.Toolkit.Security -Version 1.0.1
<PackageReference Include="Plugin.Toolkit.Security" Version="1.0.1" />
paket add Plugin.Toolkit.Security --version 1.0.1
#r "nuget: Plugin.Toolkit.Security, 1.0.1"
// Install Plugin.Toolkit.Security as a Cake Addin #addin nuget:?package=Plugin.Toolkit.Security&version=1.0.1 // Install Plugin.Toolkit.Security as a Cake Tool #tool nuget:?package=Plugin.Toolkit.Security&version=1.0.1
Plugin.Toolkit.Security
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 | Versions 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. |
-
net8.0
- System.IdentityModel.Tokens.Jwt (>= 8.3.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.