Jwt
Entry point for the KJWT library.
Create a signed JWT (JWS):
val token = Jwt.builder()
.subject("user123")
.issuer("myapp")
.expiration(Clock.System.now() + 1.hours)
.signWith(JwsAlgorithm.HS256, hmacKey)Content copied to clipboard
Parse and verify a signed JWT:
val jws = Jwt.parser()
.verifyWith(JwsAlgorithm.HS256, hmacKey)
.requireIssuer("myapp")
.build()
.parseSigned(token)
val subject = jws.payload.subjectContent copied to clipboard
Create an encrypted JWT (JWE):
val token = Jwt.builder()
.subject("user123")
.encryptWith(rsaPublicKey, JweKeyAlgorithm.RsaOaep256, JweContentAlgorithm.A256GCM)Content copied to clipboard
Decrypt a JWE:
val jwe = Jwt.parser()
.decryptWith(rsaPrivateKey)
.build()
.parseEncrypted(token)Content copied to clipboard
Note: This library depends on cryptography-core interfaces. You must register a CryptographyProvider before use. The recommended approach is to add cryptography-provider-optimal to your app dependencies — it auto-registers on startup.
Functions
Link copied to clipboard
Creates a new JwtBuilder for constructing JWS or JWE tokens.
Link copied to clipboard
Creates a new JwtParserBuilder for parsing and validating JWS or JWE tokens.