Skip to content

Instantly share code, notes, and snippets.

View Symryvvin's full-sized avatar
💭
i`m fine

Roman Symryvvin

💭
i`m fine
View GitHub Profile
@Symryvvin
Symryvvin / JWTExample.java
Last active March 3, 2021 10:15
Use RSA key for generate and validate JWT
//this is example, not best practics to use
public String generate(User user) throws TokenServiceException {
try {
PrivateKey privateKey = PemKeyUtils.privateKeyFromString(Files.readString(Paths.get("jwt_private_key.pem")));
Date date = Date.from(LocalDateTime.now().plusHours(12).atZone(ZoneId.systemDefault()).toInstant());
return Jwts.builder()
.setSubject(user.getUsername()) // username is "login"
.setExpiration(date)