title: i'm having trouble creating a JWT with JJWT library
body: <p>i'm having trouble  creating a JWT with the JJWT library : <a href="https://github.com/jwtk/jjwt" rel="nofollow noreferrer">https://github.com/jwtk/jjwt</a> </p>
  
  <p>I have followed the instructions and came up with this simple class:</p>
  
  <pre><code>import io.jsonwebtoken.Claims;
  import io.jsonwebtoken.Jws;
  import io.jsonwebtoken.Jwts;
  import io.jsonwebtoken.SignatureAlgorithm;
  import io.jsonwebtoken.security.Keys;
  import java.security.Key;
  import java.util.Calendar;
  import java.util.Date;
  
  public class Test {
      public static void main(String[] args){
  
          Date date = new Date();
          Key key = Keys.secretKeyFor(SignatureAlgorithm.HS256);
  
          Calendar cal = Calendar.getInstance();
          cal.setTime(date);
          cal.add(Calendar.HOUR, 1);
  
          Date expirationDate = cal.getTime();
  
          String jws = Jwts.builder()
                  .setSubject("user")
                  .setId("1")
                  .setIssuer("me")
                  .setIssuedAt(new Date())
                  .setExpiration(expirationDate)
                  .setIssuedAt(date)
                  .signWith(key)
                  .compact();
  
          System.out.println("jws: "+ jws);
          decode(jws);
      }
  
  
      public static Jws&lt;Claims&gt; decode(String token){
          return Jwts.parser().setSigningKey(Keys.secretKeyFor(SignatureAlgorithm.HS256)).parseClaimsJws(token);
      }
  }
  </code></pre>
  
  <p>when i run it, i get the output:</p>
  
  <pre><code>jws: eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1c2VyIiwianRpIjoiMSIsImlzcyI6InZpY3RvciIsImlhdCI6MTU3NjEwMTAyNiwiZXhwIjoxNTc2MTA0NjI2fQ.28JIsQSc273GT_qjyXEGjyh5KTJJ3thYVGQAa4ZQzvo
  </code></pre>
  
  <p>and the exception: </p>
  
  <pre><code>Exception in thread "main" io.jsonwebtoken.security.SignatureException: JWT signature does not match locally computed signature. JWT validity cannot be asserted and should not be trusted.
      at io.jsonwebtoken.impl.DefaultJwtParser.parse(DefaultJwtParser.java:383)
      at io.jsonwebtoken.impl.DefaultJwtParser.parse(DefaultJwtParser.java:513)
      at io.jsonwebtoken.impl.DefaultJwtParser.parseClaimsJws(DefaultJwtParser.java:573)
      at Test.decode(Test.java:38)
      at Test.main(Test.java:33)
  </code></pre>
  
  <p>Also when i paste my jwt on this site : <a href="https://jwt.io/" rel="nofollow noreferrer">https://jwt.io/</a>
  it gives me the correct (i presume) header:</p>
  
  <pre><code>{
    "alg": "HS256"
  }
  </code></pre>
  
  <p>and the correct payload:</p>
  
  <pre><code>{
    "sub": "user",
    "jti": "1",
    "iss": "victor",
    "iat": 1576100934,
    "exp": 1576104534
  }
  </code></pre>
  
  <p>but it says the signature is invalid.</p>
  
  <p>What am I doing wrong? How do i create the signature correctly?</p>