Enum Hasher

    • Enum Constant Detail

      • MD5

        public static final Hasher MD5
      • SHA_1

        public static final Hasher SHA_1
      • SHA_256

        public static final Hasher SHA_256
      • SHA_384

        public static final Hasher SHA_384
      • SHA_512

        public static final Hasher SHA_512
    • Field Detail

      • DEFAULT_ENCODING

        public static final Charset DEFAULT_ENCODING
      • digestLength

        public final int digestLength
    • Method Detail

      • values

        public static Hasher[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (Hasher c : Hasher.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static Hasher valueOf​(String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        IllegalArgumentException - if this enum type has no constant with the specified name
        NullPointerException - if the argument is null
      • valueOf

        public static Hasher valueOf​(int length)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        length - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        IllegalArgumentException - if this enum type has no constant with the specified name
        NullPointerException - if the argument is null
      • getHex

        public static String getHex​(byte[] raw)
      • hash

        public String hash​(String message,
                           Charset charset)
        Hash message String with algorithm and charset
        Parameters:
        message - the String to hash
        charset - the charset to use for message
        Returns:
        the corresponding hash code String; empty if algorithm is UNKNOWN or NONE or if message is empty.
      • hash

        public String hash​(Path filePath)
        Hash message from Path
        Parameters:
        filePath - representing the message to hash
        Returns:
        the corresponding hash code String; empty if algorithm is UNKNOWN or NONE or nothing to take from stream.
      • hash

        public String hash​(Path filePath,
                           String prefix)
        Hash message from Path and string prefix
        Parameters:
        filePath - representing the message to hash
        Returns:
        the corresponding hash code String; empty if algorithm is UNKNOWN or NONE or nothing to take from stream.
      • hash

        public String hash​(InputStream stream)
        Hash message from InputStream
        Parameters:
        stream - the message to hash
        Returns:
        the corresponding hash code String; empty if algorithm is UNKNOWN or NONE or nothing to take from stream.
      • parse

        public static Optional<Hasher> parse​(String algo)
        Parse Hasher value from String
        Parameters:
        algo - the algorithm name as a String
        Returns:
        the corresponding Optional Enum value if successful; empty Optional otherwise
      • shorten

        public static String shorten​(String s,
                                     int l)
      • hash

        public byte[] hash​(byte[] buffer)