Created
July 26, 2017 17:02
-
-
Save lenew/56825949ca2bc8c4cc35a32a55805947 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.IdentityModel.Tokens; | |
using System; | |
using System.IdentityModel.Tokens.Jwt; | |
using System.Text; | |
namespace JwtTest | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var keyBytes = new byte[64]; | |
var passwordBytes = Encoding.UTF8.GetBytes("security"); | |
Buffer.BlockCopy(passwordBytes, 0, keyBytes, 0, passwordBytes.Length); | |
SymmetricSecurityKey key = new SymmetricSecurityKey(keyBytes); | |
JwtHeader header = new JwtHeader(new Microsoft.IdentityModel.Tokens.SigningCredentials(key, "HS256")); | |
JwtPayload payload = new JwtPayload(); | |
payload.Add("sub", "1234567890"); | |
payload.Add("name", "John Doe"); | |
payload.Add("admin", true); | |
JwtSecurityToken token = new JwtSecurityToken(header, payload); | |
JwtSecurityTokenHandler h = new JwtSecurityTokenHandler(); | |
Console.WriteLine(h.WriteToken(token)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment