A salt is a random value added to an input before hashing or encryption. It makes the operation stronger by increasing the difficulty of reversing the result. section 4.1.4
Spring Security provides key generators for producing salt values:
- StringKeyGenerator returns a salt as a string, typically encoded from an 8-byte key as hexadecimal. section 4.2.1
- BytesKeyGenerator returns raw bytes and reports the generated key length; secureRandom() uses 8 bytes by default. section 4.2.1
- secureRandom(16) requests 16-byte keys, while shared(16) returns the same key for repeated calls from one generator. section 4.2.1
Generating a string salt
Create a StringKeyGenerator with KeyGenerators.string(), then call generateKey() to obtain the salt.




