- JSON Formatter/Viewer
Format, minify, visualize and validate JSON.
- JSON Diff
Compare two JSON objects.
- JSON Schema Validator
Validate JSON schema online
- Base64 Encode/Decode
Encode and decode Base64.
- URL Encode/Decode
Encode and decode URL.
- UUID Generator v4 / v1
Generate UUIDs in v4 and other versions.
- Text Hash
Generate cryptographic hashes from your text input using a wide variety of algorithms.
- File Hash
Generate cryptographic hashes from your file using a wide variety of algorithms.
- JWT Decoder & Validator
Decode and validate JSON Web Tokens.
- CSV Viewer
View CSV data in a table.
- CSV to JSON Converter
Convert CSV to JSON.
- JSON to CSV Converter
Convert JSON to CSV.
C# Decode JWT
This guide provide insights on decoding JWT in C#. The snippet below demonstrates a practical example of JWT decoding using C#.
private static void DecodeJwt(string token, string key)
{
var secretKey = Encoding.UTF8.GetBytes(key);
var validationParameters = new TokenValidationParameters
{
ValidateIssuer = false,
ValidateAudience = false,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(secretKey)
};
var principal = new JwtSecurityTokenHandler().ValidateToken(token, validationParameters, out var validatedToken);
}
This C# snippet decodes a JWT (JSON Web Token). It uses a method called DecodeJwt, which accepts the JWT token and a key as parameters.
The key is converted to a byte array using UTF8 Encoding. A new TokenValidationParameters object is created with necessary validation flags set to true. The IssuerSigningKey is produced by the byte array.
Finally, the ValidateToken method of JwtSecurityTokenHandler is used to validate and decode the JWT. The decoded token is stored in a variable called principal.