using System.Collections.Generic;
using System.Security.Cryptography;
public static void Main()
var iat = Math.Round((DateTime.UtcNow.AddMinutes(-1) - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds, 0);
var exp = Math.Round((DateTime.UtcNow.AddMinutes(30) - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds, 0);
var payload = new Dictionary<string, object>()
{ "origin", "My domain name" }
var extraHeader = new Dictionary<string, object>()
var keyString = "the content of my .p8 downloaded private key, when I created the key in https://developer.apple.com/account/ios/authkey/create";
CngKey privateKey = CngKey.Import(Convert.FromBase64String(keyString), CngKeyBlobFormat.Pkcs8PrivateBlob);
string token = JWT.Encode(payload, privateKey, JwsAlgorithm.ES256, extraHeader);
Console.WriteLine(token);