Performance: JWT generation
MEDIUM IMPACT
JWT generation affects server response time and CPU usage during authentication processes.
Key key = Keys.hmacShaKeyFor(secretKey.getBytes(StandardCharsets.UTF_8)); String token = Jwts.builder() .setSubject(user.getUsername()) .setExpiration(Date.from(Instant.now().plus(1, ChronoUnit.HOURS))) .signWith(key, SignatureAlgorithm.HS256) .compact();
String token = Jwts.builder()
.setSubject(user.getUsername())
.setExpiration(new Date(System.currentTimeMillis() + 3600000))
.signWith(SignatureAlgorithm.HS256, secretKey.getBytes())
.compact();| Pattern | CPU Usage | Response Delay | Security Impact | Verdict |
|---|---|---|---|---|
| Raw byte key with deprecated signWith | High | 10-20ms delay | Potential security risk | [X] Bad |
| Proper Key object with modern API | Low | 5-10ms delay | Secure and efficient | [OK] Good |