title: How do I generate a SALT in Java for Salted-Hash?
body: <p>I've been looking around and the closest answer is : <a href="https://stackoverflow.com/questions/41107/how-to-generate-a-random-alpha-numeric-string">How to generate a random alpha-numeric string?</a></p>
  <p>I want to follow this workflow according to this <a href="https://crackstation.net/hashing-security.htm#salt" rel="noreferrer">CrackStation tutorial</a>:</p>
  <blockquote>
  <p><strong>To Store a Password</strong></p>
  <ol>
  <li><p>Generate a long random salt using a CSPRNG.</p>
  </li>
  <li><p>Prepend the salt to the password and hash it with a standard cryptographic hash function such as SHA256.</p>
  </li>
  <li><p>Save both the salt and the hash in the user's database record.</p>
  </li>
  </ol>
  <p><strong>To Validate a Password</strong></p>
  <ol>
  <li><p>Retrieve the user's salt and hash from the database.</p>
  </li>
  <li><p>Prepend the salt to the given password and hash it using the same hash function.</p>
  </li>
  <li><p>Compare the hash of the given password with the hash from the database. If they match, the password is correct. Otherwise, the password is incorrect.</p>
  </li>
  </ol>
  </blockquote>
  <p>I don't know how to generate a SALT. I figured out how to generate a hash using the MessageDigest. I tried using <em>SecureRandom</em> but nextByte method produces garbled code.</p>
  <p><strong>Edit:</strong> I don't know which answer to choose, they're too complicated for me, I have decided to use jBCrypt; jBCript is easy to use, does all the complex stuff behind the scenes. so I'll let the community vote up for the best answer.</p>