1

I have a keystore where I have to insert a key to encode/decode my jwts. I know that jwts can be created by using many alghorithms (in my case I would have to use hmac-sha512) but how this relates to java secret key?

Could you please show me how to generare a secret key on the fly, what requirements it should have?

Phate
  • 5,412
  • 12
  • 62
  • 112

1 Answers1

1

Do you mean something like this?

    SecretKey generateSecretKey(String algorithmName, int keySize)
        throws Exception {
    KeyGenerator keygen = KeyGenerator.getInstance("HmacSHA512");
    keygen.init(keySize);

    return keygen.generateKey();
}

You can also check this answer.

fjsv
  • 705
  • 9
  • 22