O'Reilly logo

Instant Java Password and Authentication Security by Fernando Mayoral

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a strong hash (Simple)

This task involves a stronger hashing method to create strong cryptographic hashes.

How to do it...

The following are the steps to create a strong hash:

  1. Get the password value as plain text.
  2. Get a SHA-1 MessageDigest instance.
  3. Put the password string in the MessageDigest instance.
  4. Execute the digest method to get the hash byte array.
  5. Encode each byte to a Hexadecimal format into a String Builder.
  6. Get the built string from the StringBuilder method.
  7. The built string is a Hexadecimal representation of the SHA-1 Hash.
  8. The password can now be stored.

In the following screenshot is the code in Java that allows us to create a SHA-1 Hash. It's exactly the same as the MD5 hash, except that we will get a MessageDigest instance using ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required