Class SaslUtils

java.lang.Object
com.lucimber.dbus.util.SaslUtils

public final class SaslUtils extends Object
Utility class for common methods used for SASL authentication.
  • Method Details

    • toHexadecimalString

      public static String toHexadecimalString(byte[] bytes)
      Translates a byte-array to its corresponding hexadecimal representation.
      Parameters:
      bytes - The byte-array
      Returns:
      The hexadecimal representation as a String.
    • fromHexadecimalString

      public static byte[] fromHexadecimalString(String hexString)
      Translates a hexadecimal string to its corresponding binary representation.
      Parameters:
      hexString - The hexadecimal string
      Returns:
      The binary representation as a byte-array.
    • generateChallengeString

      public static String generateChallengeString(int challengeLength)
      Generates an ASCII-safe challenge string.
      Parameters:
      challengeLength - The desired length of the challenge.
      Returns:
      The challenge as a String.
    • locateCookieFile

      public static Path locateCookieFile(Path directoryPath, String cookeFileName) throws FileNotFoundException, AccessDeniedException
      Locates the cookie file for the DBUS_COOKIE_SHA1 authentication mechanism.
      Parameters:
      directoryPath - The path of the directory in which the file resides.
      cookeFileName - The name of the cookie file.
      Returns:
      The resolved path of the cookie file.
      Throws:
      FileNotFoundException - If the resolved path points to no (regular) file.
      AccessDeniedException - If the cookie file cannot be accessed by the VM.
    • computeHashValue

      public static byte[] computeHashValue(byte[] bytes) throws NoSuchAlgorithmException
      Computes a hash value via the SHA.
      Parameters:
      bytes - The bytes that should be hashed.
      Returns:
      The hash as a byte-array.
      Throws:
      NoSuchAlgorithmException - If the JVM is not capable of computing the hash via SHA.