Я пытаюсь создать JWT, ссылаясь на такие документы, как https://stormpath.com/blog/jwt-java-create-verify
Однако я получаю сообщение об ошибке
java.lang.IllegalArgumentException: RSA signatures be computed using a PrivateKey.Object of class [javax.crypto.spec.SecretKeySpec] must be an instance of interface java.security.PrivateKey
эта ошибка возникает в построителе .compact ().
Мне интересно, связано ли это с тем, что signedKey является Typed Key, а не PrivateKey, но ввод или преобразование сами по себе вызывают другие ошибки.
ниже мой код.
public static String createJWT() {
//The JWT signature algorithm we will be using to sign the token
SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.RS256;
//We will sign our JWT with our ApiKey secret
byte[] apiKeySecretBytes = DatatypeConverter.parseBase64Binary(SECRET_KEY);
Key signingKey = new SecretKeySpec(apiKeySecretBytes, signatureAlgorithm.getJcaName());
//Let's set the JWT Claims
JwtBuilder builder = Jwts.builder()
.setNotBefore(new Date())
.setIssuedAt(new Date())
.setExpiration(new Date())
.signWith(signatureAlgorithm, signingKey);
//Builds the JWT and serializes it to a compact, URL-safe string
String jwt = builder.compact();
return jwt;
}