CSharp · Console
using System;
using System.Collections.Generic;
using Jose;
public class Program
{
public static void Main()
{
string token = "";
byte[] secretKey = null;
Dictionary<string, object> payload = new Dictionary<string, object>()
{
{ "sub", "[email protected]" },
{ "exp", 1300819380 }
};
// Creating Plaintext (unprotected) Tokens
// https://github.com/dvsekhvalnov/jose-jwt#creating-plaintext-unprotected-tokens
token = "";
token = JWT.Encode(payload, null, JwsAlgorithm.none);
Console.WriteLine("JwsAlgorithm.none: " + token);
// HS256, HS384, HS512
// https://github.com/dvsekhvalnov/jose-jwt#hs--family
secretKey = new byte[] { 164, 60, 194, 0, 161, 189, 41, 38, 130, 89, 141, 164, 45, 170, 159, 209, 69, 137, 243, 216, 191, 131, 47, 250, 32, 107, 231, 117, 37, 158, 225, 234 };
token = "";
token = JWT.Encode(payload, secretKey, JwsAlgorithm.HS256);
Console.WriteLine("JwsAlgorithm.HS256: " + token);
Console.WriteLine("Decoded: " + JWT.Decode(token, secretKey));
}
}