A Jwt Manager in C# for .NET Core projects
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
JwtManager Support for RS384 and RS512 algorithms Jan 3, 2019
JwtManagerTests Support for RS384 and RS512 algorithms Jan 3, 2019
.gitignore Initial commit Dec 18, 2018
JwtManager.sln Update sln file Dec 18, 2018
LICENSE Initial commit Dec 18, 2018
Readme.md Support for RS384 and RS512 algorithms Jan 3, 2019

Readme.md

JWT RS256 C# library

A C# class that can sign and validate JWT tokens, wrapped in a simple library with a couple of helper functions.

To generate a compatible private key

openssl genrsa -out private.key 4096

To generate a compatible public key

openssl rsa -in private.key -outform PEM -pubout -out public.pem

Sign a JWT token

using Newtonsoft.Json;

JwtManager.RsJwt jwt = new JwtManager.RsJwt
{
    KeySize = 256, // This can be also 384 or 512
    PrivateKey = PrivateKey
};

string strToken = JsonConvert.SerializeObject(myToken);
string signedToken = jwt.Sign(strToken);

In case of an error, an Exception will be thrown.

Validate a JWT token

using Newtonsoft.Json;

JwtManager.RsJwt jwt = new JwtManager.RsJwt
{
    KeySize = 256, // This can be also 384 or 512
    PublicKey = PublicKey
};

string payload = jwt.Validate(strToken);
var myToken JsonConvert.DesrializeObject<JwtToken>(payload);

In case of an error, an Exception will be thrown.

The code has been tested both as a .NET and .NET Core library.

Check the Tests projects on more examples on how to use