Skip to content

Instantly share code, notes, and snippets.

@theblang
Created July 28, 2015 20:24
Show Gist options
  • Save theblang/5f3ceb8214c2e90c948f to your computer and use it in GitHub Desktop.
Save theblang/5f3ceb8214c2e90c948f to your computer and use it in GitHub Desktop.
Decode JWT in Java without the secret using JJWT
String token = Jwts.builder()
.setExpiration(new Date())
.setSubject("Joe")
.signWith(SignatureAlgorithm.HS512, MacProvider.generateKey())
.compact();
System.out.println(token);
String[] pieces = token.split("\\.");
System.out.println(pieces[1]);
try {
System.out.println(new String(DatatypeConverter.parseBase64Binary(pieces[1]), "UTF-8"));
} catch (UnsupportedEncodingException ex) {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment