@@ -122,24 +122,34 @@ Most web applications use JWT to authorize a user, and Dotenvx Spring Boot
122122uses [ Nimbus JOSE + JWT] ( https://connect2id.com/products/nimbus-jose-jwt ) to generate and verify JWT token.
123123
124124``` java
125- @Test
126- public void testGenerateJwt() throws Exception {
127- final ECKeyPair keyPair = Ecies . generateEcKeyPair();
128- String subject = " example-user" ;
129- JWTClaimsSet claimsSet = new JWTClaimsSet .Builder ()
130- .subject(subject)
131- .issuer(" dotenvx" )
132- .issueTime(new Date ())
133- .expirationTime(new Date (System . currentTimeMillis() + 3600000 )) // 1 hour expiration
134- .build();
135- final BCECPublicKey publicKey = keyPair. getPublic();
136- final BCECPrivateKey privateKey = keyPair. getPrivate();
137- final String jwtToken = Secp256k1JwtService . createJwtToken(privateKey, claimsSet);
138- final JWTClaimsSet jwtClaimsSet = Secp256k1JwtService . verifyJwt(jwtToken, publicKey);
139- assertThat(jwtClaimsSet. getSubject()). isEqualTo(subject);
140- }
125+
126+ @Test
127+ public void testGenerateJwt() throws Exception {
128+ final ECKeyPair keyPair = Ecies . generateEcKeyPair();
129+ String subject = " example-user" ;
130+ JWTClaimsSet claimsSet = new JWTClaimsSet .Builder ()
131+ .subject(subject)
132+ .issuer(" dotenvx" )
133+ .issueTime(new Date ())
134+ .expirationTime(new Date (System . currentTimeMillis() + 3600000 )) // 1 hour expiration
135+ .build();
136+ final BCECPublicKey publicKey = keyPair. getPublic();
137+ final BCECPrivateKey privateKey = keyPair. getPrivate();
138+ final String jwtToken = Secp256k1JwtService . createJwtToken(privateKey, claimsSet);
139+ final JWTClaimsSet jwtClaimsSet = Secp256k1JwtService . verifyJwt(jwtToken, publicKey);
140+ assertThat(jwtClaimsSet. getSubject()). isEqualTo(subject);
141+ }
141142```
142143
144+ For more, please refer to the following Java classes:
145+
146+ - [ Ecies] ( dotenvx-spring-boot/src/main/java/org/mvnsearch/dotenvx/ecies/Ecies.java ) : generate a key pair
147+ - [ Secp256k1KeyParser] ( dotenvx-spring-boot/src/main/java/org/mvnsearch/dotenvx/jwt/Secp256k1KeyParser.java ) :
148+ public/private key parser
149+ - [ Secp256k1JwtService] ( dotenvx-spring-boot/src/main/java/org/mvnsearch/dotenvx/jwt/Secp256k1JwtService.java ) : JWT
150+ Service
151+ - [ Secp256k1Signer] ( dotenvx-spring-boot/src/main/java/org/mvnsearch/dotenvx/jwt/Secp256k1Signer.java ) : signature service
152+
143153# Credits
144154
145155* jasypt-spring-boot: https://github.com/ulisesbocchio/jasypt-spring-boot
0 commit comments