I want to produce JWTs and sign them with HMAC_SHA256. For that task I must use jose4j. I have tried to generate key based on secret with:
SecretKeySpec key = new SecretKeySpec(("secret").getBytes("UTF-8"), AlgorithmIdentifiers.HMAC_SHA512);
but it generates 40bits key while 512bit one is required for signing using HMAC_SHA256.
- The primary issue - how to sign tokens with HMAC_SHA512 using jose4j?
- Issue created by my approach solving issue above - how to make 512bit long secret key based on secret string?
A common approach is to hash the secret before using it as a signing key.
The alternative is to relax the requirement on the key length with something like: