Skip to content

Instantly share code, notes, and snippets.

@dehidehidehi
Created July 28, 2022 08:47
Show Gist options
  • Save dehidehidehi/2c674386ce744c04e9d5168d68416f83 to your computer and use it in GitHub Desktop.
Save dehidehidehi/2c674386ce744c04e9d5168d68416f83 to your computer and use it in GitHub Desktop.
Decodes JWT from Base64 to a StringArray
static byte[] decodeBase64(String encoded) {
return Base64.getDecoder().decode(encoded);
}
static String[] decodeJwt(String encodedIdToken) {
String[] splitIdToken = encodedIdToken.split("\\.");
String header = new String(decodeBase64(splitIdToken[0]));
String payload = new String(decodeBase64(splitIdToken[1]));
String signature = splitIdToken[2]; // decode this for later, kept on having decode errors
return {header, payload, signature};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment