Class HashUtilities

    • Method Detail

      • bytesToBase64

        public static String bytesToBase64​(byte[] bytes)
        Transforms the input byte array to Base64.

        This is intended as an input to hash(String, String, Function), as the encoder.

        Parameters:
        bytes - The input bytes
        Returns:
        A base64 string
      • bytesToHex

        public static String bytesToHex​(byte[] bytes)
        Transforms the given byte array to hexadecimal.

        This is intended as an input to hash(String, String, Function), as the encoder.

        Parameters:
        bytes - The input byte array
        Returns:
        The output as a hexadecimal string
      • hash

        public static String hash​(String hashFunction,
                                  String input)
                           throws sailpoint.tools.GeneralException
        Performs a hash of the given input with the given hash function.

        This implementation takes care of the javax.crypto initialization for you.

        Parameters:
        hashFunction - The hash function to use
        input - The input string to hash
        Returns:
        The hashed value as a hexadecimal string
        Throws:
        sailpoint.tools.GeneralException - if any cryptographic failures occur
      • hash

        public static String hash​(String hashFunction,
                                  String input,
                                  Function<byte[],​String> encoder)
                           throws sailpoint.tools.GeneralException
        Performs a hash of the given input with the given hash function.

        This method allows you to replace the encoding implementation if you don’t wish to receive your output as a hexadecimal string.

        Parameters:
        hashFunction - The hash function to use
        input - The input string to hash
        encoder - A function to encode the byte array into a String if you wish to replace the hexadecimal implementation
        Returns:
        The hashed value as a hexadecimal string
        Throws:
        sailpoint.tools.GeneralException - if any cryptographic failures occur
      • md5

        public static String md5​(String input)
                          throws sailpoint.tools.GeneralException
        Hashes the input using the MD5 algorithm and returns it as a hex string
        Parameters:
        input - The input string
        Returns:
        The MD5 hash of the input string in hex
        Throws:
        sailpoint.tools.GeneralException - if any cryptographic failures occur
      • sha256

        public static String sha256​(String input)
                             throws sailpoint.tools.GeneralException
        Hashes the input using the SHA-256 algorithm and returns it as a hex string
        Parameters:
        input - The input string
        Returns:
        The SHA-256 hash of the input string in hex
        Throws:
        sailpoint.tools.GeneralException - if any cryptographic failures occur