Class BCryptHashFunction


  • public class BCryptHashFunction
    extends HashFunction
    A cryptograhpic hash function implemented using BCrypt. This hash function can be used for creating password hashes.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String compute​(java.lang.String msg, java.lang.String salt)
      Computes the hash of a message + salt.
      java.lang.String getName()
      Returns the name for this hash function.
      static void main​(java.lang.String[] args)  
      boolean verify​(java.lang.String msg, java.lang.String salt, java.lang.String hash)
      Verifies a message with the salted hash.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • BCryptHashFunction

        public BCryptHashFunction()
    • Method Detail

      • getName

        public java.lang.String getName()
        Returns the name for this hash function. Returns "BCrypt".
        Specified by:
        getName in class HashFunction
      • compute

        public java.lang.String compute​(java.lang.String msg,
                                        java.lang.String salt)
        Description copied from class: HashFunction
        Computes the hash of a message + salt.

        The message is usually an ASCII or UTF-8 string.

        The salt and the computed hash are encoded in printable characters. This is usually ASCII-encoded or could be Base64-encoded.

        Specified by:
        compute in class HashFunction
      • verify

        public boolean verify​(java.lang.String msg,
                              java.lang.String salt,
                              java.lang.String hash)
        Description copied from class: HashFunction
        Verifies a message with the salted hash.

        The base implementation will recompute the hash of the message with the given salt, and compare it to the hash.

        Some methods however store the salt and additional settings in the hash, and this information is thus needed to verify the message hash.

        Overrides:
        verify in class HashFunction
      • main

        public static void main​(java.lang.String[] args)