Skip to content

How can I set the "alg" header? #876

Closed Answered by lhazlewood
leoneltrich asked this question in Q&A
Discussion options

You must be logged in to vote

Good question!

I'm assuming EC512 is not a typo for the RFC standard ES512 algorithm (ECDSA using P-521 and SHA-512), which JJWT natively supports via the Jwts.SIG.ES512 constant. So this implies that you're trying to implement your own custom signature (or key management) algorithm with a non-standard EC512 identifier. Based on that assumption:

The alg header is set automatically by JJWT based on the signature algorithm (for signed JWTs, aka JWSs) or key management algorithm (for encrypted JWTs, aka JWEs) specified during JWT building. For example, for JWSs:

Jwts.builder()
    .signWIth(key) // JJWT implicitly chooses the appropriate algorithm based on the key type and size, or:
   //.si…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by lhazlewood
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants