wuchimedes | 079c163 | 2025-04-02 22:01:20 +0800 | [diff] [blame] | 1 | package com.example.g8backend.config; |
| 2 | |
| 3 | |
| 4 | import io.jsonwebtoken.security.Keys; |
| 5 | import org.springframework.context.annotation.Bean; |
| 6 | import org.springframework.context.annotation.Configuration; |
| 7 | import javax.crypto.SecretKey; |
| 8 | import java.nio.charset.StandardCharsets; |
| 9 | |
| 10 | @Configuration |
| 11 | public class JwtConfig { |
| 12 | private static final String SECRET_KEY = "this-is-a-very-long-256-bit-secret-key-for-JWT"; // |
| 13 | private static final long EXPIRATION_MS = 3600_000; // 1小时 |
| 14 | |
| 15 | @Bean |
| 16 | public SecretKey jwtSecretKey() { |
| 17 | return Keys.hmacShaKeyFor(SECRET_KEY.getBytes(StandardCharsets.UTF_8)); |
| 18 | } |
| 19 | |
| 20 | public long getExpirationMs() { |
| 21 | return EXPIRATION_MS; |
| 22 | } |
| 23 | } |
| 24 | |