jjwt icon indicating copy to clipboard operation
jjwt copied to clipboard

Improve JwtBuilder JavaDoc to recommend to sign with a SecretKey

Open pauloleitemoreira opened this issue 10 years ago • 2 comments

Following this question opened in stackoverflow: Static secret as byte[], Key or String?. The JwtBuilder JavaDoc could have some recomendation about using SecretKey instead of byte[] or String to sign a JWT.

According with SecretKey JavaDoc:

Implementations should override the default destroy and isDestroyed methods from the Destroyable interface to enable sensitive key information to be destroyed, cleared, or in the case where such information is immutable, unreferenced.

Since MacProvider.generateKey() uses SecretKeySpec to gerenate the SecretKey, we can ensure that implementation of SecretKey is following the Oracle JavaDoc.

My suggestion is adding something like it: "Using JwtBuilder signWith(SignatureAlgorithm var1, Key var2); is more safe, because SecretKey implementation ensures to destroy sensitive key information from the memory when this object is eligible for garbage collection."

pauloleitemoreira avatar Oct 27 '16 18:10 pauloleitemoreira

Thanks for the issue! If you feel inclined to open a PR for this change, that'd be awesome ;)

lhazlewood avatar Oct 27 '16 18:10 lhazlewood

Suggestion implemented and released in 0.10.0 along with a new recommended .setSigningKey(Key) method. Thanks for the issue!

lhazlewood avatar Aug 06 '18 17:08 lhazlewood