Skip to content

Unable to compute HS512 signature with JCA algorithm 'HmacSHA512' using key {class: javax.crypto.spec.SecretKeySpec, algorithm: HmacSHA512, format: RAW}: Mac callback execution failed: No installed provider supports this key: javax.crypto.spec.SecretKeySpec #931

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

You must be logged in to vote

For what it's worth, this line in the sample code is incorrect:

byte[] keyBytes = Base64.getDecoder().decode(secret.getBytes(UTF_8));

Base64 does not use the UTF-8 charset, it uses ISO-8859-1. Changing your code to the following is more correct/accurate:

byte[] keyBytes = Base64.getDecoder().decode(secret);

Also, if you want the extra length/strength assertions to guarantee that the Base64 key's decoded bytes are valid for a JWA HMAC algorithm, I would change this line:

this.key = new SecretKeySpec(keyBytes, "HmacSHA512");

to this:

this.key = Keys.hmacShaKeyFor(keyBytes);

In summary, the total changes to the class constructor would be:

byte[] keyBytes = Base64.getDecoder().decode(secret);

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@ehddbs4521
Comment options

@bdemers
Comment options

@lhazlewood
Comment options

Answer selected by lhazlewood
Comment options

You must be logged in to vote
0 replies
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
3 participants