FGV.Lib.Security 1.0.0

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

FGV.Lib.Security

FGV.Lib.Security is a .NET library that provides security-related functionality to simplify the implementation of authentication and encryption in your applications. The library offers JWT (JSON Web Token) authentication helpers and encryption/decryption utilities.

Features

  • JWT Authentication

  • Token generation with customizable claims

  • JWT configuration for ASP.NET Core applications

  • Token validation setup

  • Cryptography

  • Encryption and decryption using AES (RijndaelManaged)

  • MD5 hashing specifically designed for medical residency platforms

Requirements

  • .NET 7.0 or higher
  • Dependencies:
  • Microsoft.AspNetCore.Authentication.JwtBearer
  • Microsoft.Extensions.Configuration
  • Microsoft.Extensions.DependencyInjection
  • System.IdentityModel.Tokens.Jwt

Installation

NuGet Package Manager

Install-Package FGV.Lib.Security

.NET CLI

dotnet add package FGV.Lib.Security

Usage

JWT Authentication Setup

Configure JWT authentication in your ASP.NET Core application:

using FGV.Lib.Security.Authentication;
using Microsoft.Extensions.DependencyInjection;

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        // Add JWT authentication
        services.AddJwtSecurity(Configuration);
        
        // Other service configurations...
    }
}

Make sure your appsettings.json includes the JWT configuration:

{
"Jwt": {
    "Key": "your-secret-key-here",
    "Issuer": "your-issuer",
    "Audience": "your-audience",
    "Expiration": 60
}
}

Generating JWT Tokens

using FGV.Lib.Security.Authentication;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;

// Get the JWT options (typically via dependency injection)
var jwtOptions = serviceProvider.GetRequiredService<IOptions<JwtOptions>>().Value;

// User ID (GUID)
var userId = Guid.Parse("user-guid-here");

// User roles/profiles
var roles = new List<string> { "Admin", "User" };

// Generate the JWT token
string token = JwtSecurity.GerarJwt(userId, roles, jwtOptions);

Using Encryption and Decryption

using FGV.Lib.Security;

// Encrypt data
string originalText = "Sensitive information";
string encryptionKey = "your-encryption-key";
string encryptedText = Criptografia.Encrypt(originalText, encryptionKey);

// Decrypt data
string decryptedText = Criptografia.Decrypt(encryptedText, encryptionKey);

Creating MD5 Hash for Medical Residency

using FGV.Lib.Security;

string input = "data-to-hash";
string hashedValue = Criptografia.CriarHashMD5ParaRM(input);

License

This project is licensed under the MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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 was computed.  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. 
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.0 858 5/29/2025