Java implementation of JSON Web Tokens. An easy way to encode and decode a JWT with Java.
- SHA256
- SHA384
- SHA512
Additional libraries
JUnit
import com.ducreyna.jwt;
String key = "secret";
try {
// Encode a JWT with default algorithm
HashMap<String, Object> payload = new HashMap<String, Object>();
payload.put("name", "ducreyna");
payload.put("admin", true);
payload.put("state", new HashMap<String, Object>());
String token = Jwt.encode(payload, key);
// Encode a JWT with an algorithm of your choice
HashMap<String, Object> payload = new HashMap<String, Object>();
payload.put("name", "ducreyna");
String token = Jwt.encode(payload, key, Algorithm.HS512);
// Decode a JWT with signature verification
Map<String, Object> decoded = Jwt.decode(token, key, true);
}
catch(Exception e) {}