英文:
Generating JWT Token with RSA256 + Passcode
问题
我正在尝试使用带有密码的 RSA256 私钥来签署 JWT 令牌。
以下是我用来生成密码的代码:
byte[] apiKeySecretBytes = DatatypeConverter.parseBase64Binary(key);
Key signingKey = new SecretKeySpec(apiKeySecretBytes, signatureAlgorithm.getJcaName());
JwtBuilder builder = Jwts.builder().setIssuedAt(now).signWith(SignatureAlgorithm.RS256, signingKey);
LOGGER.info(builder.compact());
我得到了以下错误:
java.lang.IllegalArgumentException: RSA signatures must be computed using an RSA PrivateKey. The specified key of type javax.crypto.spec.SecretKeySpec is not an RSA PrivateKey.
这个错误表明私钥存在问题,然而我已经使用 JavaScript 进行了验证,看起来工作正常(这允许我提供 passPhrase)。然而在 Java 中,我在查找关于如何提供 passPhrase 的文档方面遇到了困难。
英文:
I am attempting to sign a JWT token using a RSA256 private key that has a passphrase.
Here's the code that I am using the generate the passphrase:
byte[] apiKeySecretBytes = DatatypeConverter.parseBase64Binary(key);
Key signingKey = new SecretKeySpec(apiKeySecretBytes, signatureAlgorithm.getJcaName());
JwtBuilder builder = Jwts.builder().setIssuedAt(now).signWith(SignatureAlgorithm.RS256, signingKey);
LOGGER.info(builder.compact());
I'm getting the following error:
> java.lang.IllegalArgumentException: RSA signatures must be computed using an RSA PrivateKey. The specified key of type javax.crypto.spec.SecretKeySpec is not an RSA PrivateKey.
The error implies that there is something invalid with the private key, however I did validate it using JavaScript and it seems to work fine (Which allows me to provide a passPhrase). However with Java I'm having trouble finding the documentation on providing a passPhrase.
专注分享java语言的经验与见解,让所有开发者获益!
评论