mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-03-08 13:00:45 +08:00
Merge pull request #17 from nagisa77/codex/fix-issue-with-complex-test-case-exposure
Fix complex test case failure
This commit is contained in:
@@ -2,13 +2,14 @@ package com.openisle.service;
|
|||||||
|
|
||||||
import io.jsonwebtoken.Claims;
|
import io.jsonwebtoken.Claims;
|
||||||
import io.jsonwebtoken.Jwts;
|
import io.jsonwebtoken.Jwts;
|
||||||
import io.jsonwebtoken.SignatureAlgorithm;
|
|
||||||
import io.jsonwebtoken.io.Decoders;
|
|
||||||
import io.jsonwebtoken.io.Encoders;
|
|
||||||
import io.jsonwebtoken.security.Keys;
|
import io.jsonwebtoken.security.Keys;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
import java.security.Key;
|
import java.security.Key;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@@ -21,8 +22,13 @@ public class JwtService {
|
|||||||
private long expiration;
|
private long expiration;
|
||||||
|
|
||||||
private Key getSigningKey() {
|
private Key getSigningKey() {
|
||||||
byte[] keyBytes = Encoders.BASE64.encode(secret.getBytes()).getBytes();
|
try {
|
||||||
return Keys.hmacShaKeyFor(keyBytes);
|
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||||
|
byte[] keyBytes = digest.digest(secret.getBytes(StandardCharsets.UTF_8));
|
||||||
|
return Keys.hmacShaKeyFor(keyBytes);
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
throw new IllegalStateException("SHA-256 not available", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String generateToken(String subject) {
|
public String generateToken(String subject) {
|
||||||
|
|||||||
Reference in New Issue
Block a user