How to Create a JWT in Java with the secret base64 encoded

Using the online JWT debugger to encode and decode a JWT token I created this simple token
The secret to encode the token is

The header is { "alg": "HS256"}
The payload is { "sub": "admin", "aud": "Solr"}

When you encoded with the secret not base64 encoded, it generates the JWT

When the secret is base64 encoded it generates the JWT

Here is the Java code to generate the JWT for when the secret is not base64 encoded.

import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
public class JWTEncodeTest {
    public static void main(String[] args) {
        try {
            String secretkey="qwertypassword";

            //The JWT signature algorithm we will be using to sign the token
            String jwtToken = Jwts.builder()

        } catch (Exception e)

What am I missing in this Java code to generate the JWT with the secret base64 encoded to produce the JWT value of


1 Like