title: java.lang.IllegalArgumentException: secret key byte array cannot be null or empty
body: <p>I am using spring-boot with JWT.</p>
  
  <p><strong>Application.properties</strong></p>
  
  <pre><code>jwt.secret=xyz
  </code></pre>
  
  <p><strong>Controller.java</strong></p>
  
  <pre><code>@PostMapping(path = "/authenticate")
      public ResponseEntity&lt;?&gt; createAuthenticationToken(@RequestBody JwtRequest authenticationRequest) throws Exception {
  
          authenticate(authenticationRequest.getUsername(), authenticationRequest.getPassword());
  
          final UserDetails userDetails = userDetailsService.loadUserByUsername(authenticationRequest.getUsername());
  
          final String token = jwtTokenUtil.generateToken(userDetails);
  
          return ResponseEntity.ok(new JwtResponse(token));
      }
  </code></pre>
  
  <p><strong>JwtTokenUtil.java</strong></p>
  
  <pre><code>    @Value("${jwt.secret}")
      private String secret;
      public String generateToken(UserDetails userDetails) {
              Map&lt;String, Object&gt; claims = new HashMap&lt;&gt;();
              return doGenerateToken(claims, userDetails.getUsername());
          }
  
          private String doGenerateToken(Map&lt;String, Object&gt; claims, String subject) {
  
              return Jwts.builder().setClaims(claims).setSubject(subject).setIssuedAt(new Date(System.currentTimeMillis()))
                      .setExpiration(new Date(System.currentTimeMillis() + JWT_TOKEN_VALIDITY*1000)).signWith(SignatureAlgorithm.HS512, secret).compact();
          }
  </code></pre>
  
  <p>in the <code>jwtTokenUtil.generateToken</code> code I am getting the following error</p>
  
  <pre><code>ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalArgumentException: secret key byte array cannot be null or empty.] with root cause
  java.lang.IllegalArgumentException: secret key byte array cannot be null or empty.
      at io.jsonwebtoken.lang.Assert.notEmpty(Assert.java:204)
      at io.jsonwebtoken.impl.DefaultJwtBuilder.signWith(DefaultJwtBuilder.java:88)
      at io.jsonwebtoken.impl.DefaultJwtBuilder.signWith(DefaultJwtBuilder.java:100)
      at net.javaguides.springboot.helloworldapp.config.JwtTokenUtil.doGenerateToken(JwtTokenUtil.java:66)
      at net.javaguides.springboot.helloworldapp.config.JwtTokenUtil.generateToken(JwtTokenUtil.java:60)
      at net.javaguides.springboot.helloworldapp.controller.BasicAuthController.createAuthenticationToken(BasicAuthController.java:75)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.base/java.lang.reflect.Method.invoke(Method.java:567)
      at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:189)
      at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
      at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:800)
  </code></pre>
  
  <p>When I have given my credentials I am getting this error. the application is already validated my credentials, but while generating the token I am getting this error.</p>
  
  <p><strong>UPDATE:-</strong></p>
  
  <p>While debugging I have seen the internal code like below</p>
  
  <pre><code> @Override
      public JwtBuilder signWith(SignatureAlgorithm alg, String base64EncodedSecretKey) {
          Assert.hasText(base64EncodedSecretKey, "base64-encoded secret key cannot be null or empty.");
          Assert.isTrue(alg.isHmac(), "Base64-encoded key bytes may only be specified for HMAC signatures.  If using RSA or Elliptic Curve, use the signWith(SignatureAlgorithm, Key) method instead.");
          byte[] bytes = TextCodec.BASE64.decode(base64EncodedSecretKey);
          return signWith(alg, bytes);
      }
  </code></pre>
  
  <p>In this <code>bytes</code> I am getting null</p>