Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public static void Run()
{
var tokenHandler = new JsonWebTokenHandler();
var key = new RsaSecurityKey(RSA.Create(2048))
{
KeyId = Guid.NewGuid().ToString()
};
Jwt.SigningCredentials = new SigningCredentials(key, SecurityAlgorithms.RsaSsaPssSha256);
var lastJws = tokenHandler.CreateToken(Jwt);
Console.WriteLine($"{lastJws}{Environment.NewLine}");
// Store in filesystem
// Store HMAC os Filesystem, recover and test if it's valid
var jwk = JsonWebKeyConverter.ConvertFromRSASecurityKey(key);
File.WriteAllText("current-rsa.key", JsonConvert.SerializeObject(jwk));
var storedJwk = JsonConvert.DeserializeObject<JsonWebKey>(File.ReadAllText("current-rsa.key"));
TokenValidationParams.IssuerSigningKey = storedJwk;
var validationResult = tokenHandler.ValidateToken(lastJws, TokenValidationParams);
Console.WriteLine(validationResult.IsValid);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.