Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HMAC + SHA256 jwt secret length

I will be signing a token with SHA256 and I am wondering on the length of the secret I should put. Does having a secret key length over 256 bits have any benefits if I am using sha256. So if my key is 300 bits long is this more secure?

like image 224
user2924127 Avatar asked May 29 '15 02:05

user2924127


People also ask

How long should JWT secret be?

The minimum secret length for HMAC: A key of the same size as the hash output (for instance, 256 bits for “HS256”) or larger MUST be used with this algorithm. The minimum key length for RSA: A key of size 2048 bits or larger MUST be used with these algorithms.

How long is HMAC SHA-256?

The minimum length for an SHA-256 HMAC key is 32 bytes. A key longer than 32 bytes does not significantly increase the function strength unless the randomness of the key is considered weak. A key longer than 64 bytes will be hashed before it is used.

Does JWT use HMAC?

JWTs can be signed using a secret (with the HMAC algorithm) or a public/private key pair using RSA or ECDSA.

How do I get HMAC secret?

First, enter the plain-text and the cryptographic key to generate the code. Then, you can use select the hash function you want to apply for hashing. The default is SHA-256. Then you can submit your request by clicking on the compute hash button to generate the HMAC authentication code for you.


1 Answers

The length of the key has to be <= 512 bits because that is the size of the pads. If someone is trying to brute force your key, having a key size of 512 bits will be the most secure.

So to answer your question. Yes, having a key length 300 bits is more secure than one with length 256 bits.

like image 92
Loocid Avatar answered Oct 01 '22 19:10

Loocid