From the course: Learn Java Cryptography

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Leveraging the MessageDigest engine

Leveraging the MessageDigest engine - Java Tutorial

From the course: Learn Java Cryptography

Leveraging the MessageDigest engine

- So now that we've talked a little bit about what cryptographic hashes are, let's actually jump into the JCA, and leverage the message digest engine to create a hash. In your IDE, I'd like you to open up source, main, Java. And in the com.frankmoley.crypto package, let's create a new subpackage, called hash. And in our hash package, let's create a new Java class, called HashUtils. And now, just like we've done a couple times, here, I want to create a private static final String. We will call that SHA2_ALGORITHM, and we will set that equal to SHA-256. Now, one of the attacks on a hash is using a rainbow table, which is a pre-computed set of hash chains. We're gonna prevent that by using salt. So we need to create a method to create a random salt value. So let's do that. Public static byte array, generateRandomSalt. Now, in order to generate random bytes, we would create a byte array, and call it salt, and we're…

Contents