|
|
@ -6,7 +6,7 @@ import io.jsonwebtoken.ExpiredJwtException; |
|
|
|
import io.jsonwebtoken.JwtBuilder; |
|
|
|
import io.jsonwebtoken.JwtBuilder; |
|
|
|
import io.jsonwebtoken.Jwts; |
|
|
|
import io.jsonwebtoken.Jwts; |
|
|
|
import io.jsonwebtoken.SignatureAlgorithm; |
|
|
|
import io.jsonwebtoken.SignatureAlgorithm; |
|
|
|
import org.bouncycastle.util.encoders.Base64; |
|
|
|
import org.apache.commons.codec.binary.Base64; |
|
|
|
|
|
|
|
|
|
|
|
import javax.crypto.SecretKey; |
|
|
|
import javax.crypto.SecretKey; |
|
|
|
import javax.crypto.spec.SecretKeySpec; |
|
|
|
import javax.crypto.spec.SecretKeySpec; |
|
|
@ -23,7 +23,7 @@ public class JwtUtils { |
|
|
|
* @return String |
|
|
|
* @return String |
|
|
|
* |
|
|
|
* |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static String createJWT(Long id, String subject, long ttlMillis) { |
|
|
|
public static String createJWT(String id, String subject, long ttlMillis) { |
|
|
|
SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256; |
|
|
|
SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256; |
|
|
|
long nowMillis = System.currentTimeMillis(); |
|
|
|
long nowMillis = System.currentTimeMillis(); |
|
|
|
Date now = new Date(nowMillis); |
|
|
|
Date now = new Date(nowMillis); |
|
|
@ -41,9 +41,9 @@ public class JwtUtils { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
public static void main(String[] args) { |
|
|
|
//System.out.printf(createJWT("1","111", 10000000));
|
|
|
|
System.out.println(validateJWT(createJWT("1","123",100000))); |
|
|
|
boolean isTrue = validateJWT("eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiIxIiwic3ViIjoiMTExIiwiaXNzIjoidXNlciIsImlhdCI6MTYwMTM0MzYyNywiZXhwIjoxNjAxMzUzNjI3fQ.q5Ssg2LM1OzzgvVWqLhgP_Hko0-pfeNO5bvpUE5KQ-s"); |
|
|
|
//byte[] encodedKey = Base64.decode("DQJWT");
|
|
|
|
System.out.println(isTrue); |
|
|
|
//System.out.println(encodedKey);
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -69,7 +69,7 @@ public class JwtUtils { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static SecretKey generalKey() { |
|
|
|
public static SecretKey generalKey() { |
|
|
|
byte[] encodedKey = Base64.decode("JWTDQ123456"); |
|
|
|
byte[] encodedKey = Base64.decodeBase64("DQJWT"); |
|
|
|
SecretKey key = new SecretKeySpec(encodedKey, 0, encodedKey.length, "AES"); |
|
|
|
SecretKey key = new SecretKeySpec(encodedKey, 0, encodedKey.length, "AES"); |
|
|
|
return key; |
|
|
|
return key; |
|
|
|
} |
|
|
|
} |
|
|
|