/** * 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 * @deprecated use {@link org.jivesoftware.smack.util.SHA1#hex(String)} instead. */ @Deprecated public static synchronized String hash(String data) { return org.jivesoftware.smack.util.SHA1.hex(data); }
/** * Returns a SHA-1 digest of the given parameters as specified in <a * href="http://xmpp.org/extensions/xep-0065.html#impl-socks5">XEP-0065</a>. * * @param sessionID for the SOCKS5 Bytestream * @param initiatorJID JID of the initiator of a SOCKS5 Bytestream * @param targetJID JID of the target of a SOCKS5 Bytestream * @return SHA-1 digest of the given parameters */ public static String createDigest(String sessionID, Jid initiatorJID, Jid targetJID) { StringBuilder b = new StringBuilder(); b.append(sessionID).append(initiatorJID).append(targetJID); return SHA1.hex(b.toString()); }
public static String hex(String string) { return hex(StringUtils.toUtf8Bytes(string)); }
public BoBInfo addBoB(BoBData bobData) { // We only support SHA-1 for now. BoBHash bobHash = new BoBHash(SHA1.hex(bobData.getContent()), "sha1"); Set<BoBHash> bobHashes = Collections.singleton(bobHash); bobHashes = Collections.unmodifiableSet(bobHashes); BoBInfo bobInfo = new BoBInfo(bobHashes, bobData); bobs.put(bobHash, bobInfo); return bobInfo; }
@Test public void testHash() { // Test null // @TODO - should the StringUtils.hash(String) method be fixed to handle null input? try { SHA1.hex((String) null); fail(); } catch (NullPointerException npe) { assertTrue(true); } // Test empty String String result = SHA1.hex(""); assertEquals("da39a3ee5e6b4b0d3255bfef95601890afd80709", result); // Test a known hash String adminInHash = "d033e22ae348aeb5660fc2140aec35850c4da997"; result = SHA1.hex("admin"); assertEquals(adminInHash, result); // Test a random String - make sure all resulting characters are valid hash characters // and that the returned string is 32 characters long. String random = "jive software blah and stuff this is pretty cool"; result = SHA1.hex(random); assertTrue(isValidHash(result)); // Test junk input: String junk = "\n\n\t\b\r!@(!)^(#)@+_-\u2031\u09291\u00A9\u00BD\u0394\u00F8"; result = SHA1.hex(junk); assertTrue(isValidHash(result)); }
/** * 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 * @deprecated use {@link org.jivesoftware.smack.util.SHA1#hex(String)} instead. */ @Deprecated public static synchronized String hash(String data) { return org.jivesoftware.smack.util.SHA1.hex(data); }
public static String hex(String string) { return hex(StringUtils.toUtf8Bytes(string)); }