Class Util


  • public class Util
    extends Object
    Common login module utility methods
    Version:
    $Revision$
    Author:
    Scott.Stark@jboss.org
    • Constructor Detail

      • Util

        public Util()
    • Method Detail

      • createPasswordHash

        public static String createPasswordHash​(String hashAlgorithm,
                                                String hashEncoding,
                                                String hashCharset,
                                                String username,
                                                String password)
        Calculate a password hash using a MessageDigest.
        Parameters:
        hashAlgorithm - - the MessageDigest algorithm name
        hashEncoding - - either base64 or hex to specify the type of encoding the MessageDigest as a string.
        hashCharset - - the charset used to create the byte[] passed to the MessageDigestfrom the password String. If null the platform default is used.
        username - - ignored in default version
        password - - the password string to be hashed
        Returns:
        the hashed string if successful, null if there is a digest exception
      • createPasswordHash

        public static String createPasswordHash​(String hashAlgorithm,
                                                String hashEncoding,
                                                String hashCharset,
                                                String username,
                                                String password,
                                                DigestCallback callback)
        Calculate a password hash using a MessageDigest.
        Parameters:
        hashAlgorithm - - the MessageDigest algorithm name
        hashEncoding - - either base64 or hex to specify the type of encoding the MessageDigest as a string.
        hashCharset - - the charset used to create the byte[] passed to the MessageDigestfrom the password String. If null the platform default is used.
        username - - ignored in default version
        password - - the password string to be hashed
        callback - - the callback used to allow customization of the hash to occur. The preDigest method is called before the password is added and the postDigest method is called after the password has been added.
        Returns:
        the hashed string if successful, null if there is a digest exception
      • encodeRFC2617

        public static String encodeRFC2617​(byte[] data)
        3.1.3 Representation of digest values An optional header allows the server to specify the algorithm used to create the checksum or digest. By default the MD5 algorithm is used and that is the only algorithm described in this document. For the purposes of this document, an MD5 digest of 128 bits is represented as 32 ASCII printable characters. The bits in the 128 bit digest are converted from most significant to least significant bit, four bits at a time to their ASCII presentation as follows. Each four bits is represented by its familiar hexadecimal notation from the characters 0123456789abcdef. That is, binary 0000 getInfos represented by the character '0', 0001, by '1', and so on up to the representation of 1111 as 'f'.
        Parameters:
        data - - the raw MD5 hash data
        Returns:
        the encoded MD5 representation
      • encodeBase16

        public static String encodeBase16​(byte[] bytes)
        Hex encoding of hashes, as used by Catalina. Each byte is converted to the corresponding two hex characters.
      • encodeBase64

        public static String encodeBase64​(byte[] bytes)
        BASE64 encoder implementation. Provides encoding methods, using the BASE64 encoding rules, as defined in the MIME specification, rfc1521.
      • tob64

        public static String tob64​(byte[] buffer)