Skip to content

Commit 20a76dd

Browse files
committed
Updated Readme.md
1 parent 2c21ff1 commit 20a76dd

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

Readme.md

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
# JWT RSA C# library
1+
# JWT C# library
22

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

5+
## RSA Algorithm
6+
57
To generate a compatible private key
68
```
79
openssl genrsa -out private.key 4096
@@ -12,7 +14,7 @@ To generate a compatible public key
1214
openssl rsa -in private.key -outform PEM -pubout -out public.pem
1315
```
1416

15-
## Sign a JWT token
17+
### Sign a JWT token
1618
```cs
1719
using Newtonsoft.Json;
1820

@@ -27,13 +29,13 @@ string signedToken = jwt.Sign(strToken);
2729
```
2830
In case of an error, an Exception will be thrown.
2931

30-
## Validate a JWT token
32+
### Validate a JWT token
3133
```cs
3234
using Newtonsoft.Json;
3335

3436
JwtManager.RsJwt jwt = new JwtManager.RsJwt
3537
{
36-
KeySize = JwtManager.Helpers.KeySize.S256, // This can be also 384 or 512
38+
KeySize = JwtManager.Helpers.KeySize.S256, // This can be also S384 or S512
3739
PublicKey = PublicKey
3840
};
3941

@@ -43,6 +45,48 @@ var myToken = JsonConvert.DeserializeObject<JwtToken>(payload);
4345

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

48+
49+
## HMAC Algorithm
50+
51+
For this you need a secret in store it in a string variable. Use a longer secret for better security
52+
53+
### Sign a JWT token
54+
```cs
55+
using Newtonsoft.Json;
56+
57+
string secret = "setyourverysecretkeyhere";
58+
59+
JwtManager.HsJwt jwt = new JwtManager.HsJwt
60+
{
61+
KeySize = JwtManager.Helpers.KeySize.S256, // This can be also 384 or 512
62+
Secret = secret
63+
};
64+
65+
string strToken = JsonConvert.SerializeObject(myToken);
66+
string signedToken = jwt.Sign(strToken);
67+
```
68+
In case of an error, an Exception will be thrown.
69+
70+
### Validate a JWT token
71+
```cs
72+
using Newtonsoft.Json;
73+
74+
string secret = "setyourverysecretkeyhere";
75+
76+
JwtManager.HsJwt jwt = new JwtManager.HsJwt
77+
{
78+
KeySize = JwtManager.Helpers.KeySize.S256, // This can be also S384 or S512
79+
Secret = secret
80+
};
81+
82+
string payload = jwt.Validate(strToken);
83+
var myToken = JsonConvert.DeserializeObject<JwtToken>(payload);
84+
```
85+
86+
In case of an error, an Exception will be thrown.
87+
88+
## Other Info
89+
4690
The code has been tested both as a .NET and .NET Core library.
4791

4892
Check the JwtManagerTests project on more examples on how to use

0 commit comments

Comments
 (0)