public final class Utils extends Object
Modifier and Type | Method and Description |
---|---|
static String |
base64urlDecode(String s)
Base64url decodes the given String and converts the decoded bytes into a UTF-8 String.
|
static String |
base64urlEncode(String s)
Base64url encodes the given String, converting the String to UTF-8 bytes.
|
static boolean |
constantEquals(byte[] a,
byte[] b)
Compares two byte arrays for equality, in a constant time.
|
static Map<String,Object> |
parseJson(String json)
Parses the given JSON string into a NoDuplicatesMap.
|
static String |
writeJsonObject(Map<String,Object> object)
Writes the given map as a string in JSON object format.
|
public static final Charset CHARSET
public static String base64urlEncode(String s)
s
- The String to encoded.public static String base64urlDecode(String s)
s
- The Base64url encoded String to decode.public static boolean constantEquals(byte[] a, byte[] b)
If the two byte arrays don't match the method will not return until the whole byte array has been checked. This prevents timing attacks. Unless the two arrays are not off equal length, and in this case the method will return immediately.
a
- One of the byte arrays to compare.b
- The other byte array to compare.true
if the arrays are equal, false
otherwise.public static Map<String,Object> parseJson(String json)
The JWT specification details that any JWT with duplicate header parameters or claims MUST be rejected so a Map implementation is used to parse the JSON which will throw an exception if an entry with the same key is added to the map more than once.
json
- The JSON string to parse.InvalidJwtException
- if the json value is not well formed or contains duplicate keys.public static String writeJsonObject(Map<String,Object> object)
object
- the object to write as JSON.InvalidJwtException
- if the object cannot be converted to JSON for any reason.Copyright © 2025 Open Identity Platform Community. All rights reserved.