public final class Utils extends Object
Modifier and Type | Method and Description |
---|---|
static String |
base64urlDecode(String s)
Deprecated.
|
static String |
base64urlEncode(String s)
Deprecated.
|
static boolean |
constantEquals(byte[] a,
byte[] b)
Compares two byte arrays for equality, in a constant time.
|
static String |
decodeJwtComponent(String s)
Decodes the given String and converts the decoded bytes into a UTF-8 String.
|
static String |
encodeJwtComponent(String s)
Encodes the given String, converting the String to UTF-8 bytes.
|
static Map<String,Object> |
parseJson(String json)
Parses the given JSON string into a NoDuplicatesMap.
|
static byte[] |
reverse(byte[] xs)
Reverses the given array and returns the reversed copy.
|
static byte[] |
sha256(byte[] data)
Convenience method to perform SHA-256 hashing of the input data.
|
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)
Utils.encodeJwtComponent(String)
.s
- The String to encode.public static String base64urlDecode(String s)
Utils.decodeJwtComponent(String)
.s
- The Base64url encoded String to decode.public static String encodeJwtComponent(String s)
s
- The String to encode.public static String decodeJwtComponent(String s)
s
- The 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.public static byte[] sha256(byte[] data)
data
- the data to hash.public static byte[] reverse(byte[] xs)
xs
- the array to reverse.Copyright © 2010-2018, ForgeRock All Rights Reserved.