src/main/java/org/jivesoftware/smack/util/StringUtils.java
public synchronized static String hash(String data) {
        if (digest == null) {
            try {
                digest = MessageDigest.getInstance("SHA-1");
            } catch (NoSuchAlgorithmException nsae) {
                log.log(Level.ERROR,
                        "Failed to load the SHA-1 MessageDigest. Smack will be unable to function normally.",
                        nsae);
            }
        }
        // Now, compute hash.
        try {
            digest.update(data.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            log.log(Level.ERROR, "Error computing hash", e);
        }
        return encodeHex(digest.digest());
    }
public synchronized static String hash(String data) {
        if (digest == null) {
            try {
                digest = MessageDigest.getInstance("SHA-1");
            } catch (NoSuchAlgorithmException nsae) {
                log.log(Level.ERROR,
                        "Failed to load the SHA-1 MessageDigest. Smack will be unable to function normally.",
                        nsae);
            }
        }
        // Now, compute hash.
        try {
            digest.update(data.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            log.log(Level.ERROR, "Error computing hash", e);
        }
        return encodeHex(digest.digest());
    }
public synchronized static String hash ( String data ) { if ( digest == null ) { try { digest = MessageDigest . getInstance ( "SHA-1" ) ; } catch ( NoSuchAlgorithmException nsae ) { log . log ( Level . ERROR , "Failed to load the SHA-1 MessageDigest. Smack will be unable to function normally." , nsae ) ; } } // Now, compute hash. try { digest . update ( data . getBytes ( "UTF-8" ) ) ; } catch ( UnsupportedEncodingException e ) { log . log ( Level . ERROR , "Error computing hash" , e ) ; } return encodeHex ( digest . digest ( ) ) ; }
Hashes a String using the SHA-1 algorithm and returns the result as a
String of hexadecimal numbers. This method is synchronized to avoid
excessive MessageDigest object creation. If calling this method becomes a
bottleneck in your code, you may wish to maintain a pool of MessageDigest
objects instead of using this method.
<p>
A hash is a one-way function -- that is, given an input, an output is
easily computed. However, given the output, the input is almost
impossible to compute. This is useful for passwords since we can store
the hash and a hacker will then have a very hard time determining the
original password.

@param data
the String to compute the hash of.
@return a hashed version of the passed-in String
Hashes a String using the SHA - 1 algorithm and returns the result as a String of hexadecimal numbers . This method is synchronized to avoid excessive MessageDigest object creation . If calling this method becomes a bottleneck in your code you may wish to maintain a pool of MessageDigest objects instead of using this method . <p > A hash is a one - way function -- that is given an input an output is easily computed . However given the output the input is almost impossible to compute . This is useful for passwords since we can store the hash and a hacker will then have a very hard time determining the original password .