Package com.identityworksllc.iiq.common
Class HashUtilities
- java.lang.Object
-
- com.identityworksllc.iiq.common.HashUtilities
-
public class HashUtilities extends Object
Utilities to return hexadecimal hashes of strings
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
bytesToBase64(byte[] bytes)
Transforms the input byte array to Base64.static String
bytesToHex(byte[] bytes)
Transforms the given byte array to hexadecimal.static String
hash(String hashFunction, String input)
Performs a hash of the given input with the given hash function.static String
hash(String hashFunction, String input, Function<byte[],String> encoder)
Performs a hash of the given input with the given hash function.static String
md5(String input)
Hashes the input using the MD5 algorithm and returns it as a hex stringstatic String
sha256(String input)
Hashes the input using the SHA-256 algorithm and returns it as a hex string
-
-
-
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 useinput
- 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 useinput
- The input string to hashencoder
- 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
-
-