signWith for RSA512 #942
Unanswered
lost-jwt-users
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Hi there! The older https://github.com/jwtk/jjwt?tab=readme-ov-file#signaturealgorithm-override With that, your example might look like this: return Jwts.builder()
.claims(claims)
.subject(username)
.issuedAt(issuedAt)
.expiration(expiration.getTime())
.signWith(getPrivateKey(), Jwts.SIG.RS512) // <---
.compact(); I hope that helps! Feel free to ask any follow-up questions :) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to build a JWT Token using the RSA512 signing algorithm.
My first attempt was to do the following:
However, when I run my code, it fails with the following error:
"Unable to determine a suitable MAC or Signature algorithm for the specified key using available heuristics: either the key size is too weak to be used with available algorithms, or the key size is unavailable (e.g. if using a PKCS11 or HSM (Hardware Security Module) key storage). If you are using a PKCS11 or HSM keystore, consider using the JwtBuilder.signWith(Key, SecureDigestAlgorithm) method instead."
I think that the solution is to use a signWith method which also takes the signature algorithm like this:
.signWith(getPrivateKey(), SignatureAlgorithm.RS512)
or
.signWith(SignatureAlgorithm.RS512, getPrivateKey())
but both of those method signatures are deprecated. What is the non-deprecated way to specify the SignatureAlgorithm?
There is a method in the javadoc with a signature of signWith(K key, SecureDigestAlgorithm), but I can't find any example on google of allowed SecureDigestAlgorithm - if I try:
.signWith(getPrivateKey(), SecureDigestAlgorithm.RS512)
it doesn't even compile since there isn't any set of pre-defined algorithms inside the SecureDigestAlgorithm interface.
Any hints/tips would be appreciated. Thanks.
Beta Was this translation helpful? Give feedback.
All reactions