liveBook · Manning

Cryptographic salt

As explained in Spring Security in Action, Second Edition

A salt is additional key-like data combined with an input before a hashing or cryptographic operation to make repeated inputs produce distinct results.

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.

How Spring Security in Action, Second Edition covers it

How deep it goes
Defines the security role and shows Spring Security generators, but stops short of implementing a complete hashing workflow.
Examples
Uses StringKeyGenerator, secureRandom byte generators, configurable key lengths, and shared keys.
What it assumes
Assumes hashing or encryption as the operation receiving the added value.
What you can do after
Apply it via Spring Security's KeyGenerators to produce string or byte salt values.
How it connects
Connects hashing, encryption, key generators, and password encoding.

Also explained in

Compare how 5 books explain cryptographic salt →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Security in Action, Second Edition. The section links point to the parts of the book it draws on.