From 19a8e22721900133d3a7cbe564c929f58fdf33c7 Mon Sep 17 00:00:00 2001 From: samskivert Date: Tue, 17 Feb 2009 18:56:47 +0000 Subject: [PATCH] Allow the caller to get the raw md5 bytes. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2532 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- src/java/com/samskivert/util/StringUtil.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/java/com/samskivert/util/StringUtil.java b/src/java/com/samskivert/util/StringUtil.java index 5a694571..7733bb8c 100644 --- a/src/java/com/samskivert/util/StringUtil.java +++ b/src/java/com/samskivert/util/StringUtil.java @@ -815,6 +815,14 @@ public class StringUtil return data; } + /** + * Encodes the supplied source text into an MD5 hash. + */ + public static byte[] md5 (String source) + { + return digest("MD5", source); + } + /** * Returns a hex string representing the MD5 encoded source. * @@ -822,7 +830,7 @@ public class StringUtil */ public static String md5hex (String source) { - return digest("MD5", source); + return hexlate(md5(source)); } /** @@ -832,7 +840,7 @@ public class StringUtil */ public static String sha1hex (String source) { - return digest("SHA-1", source); + return hexlate(digest("SHA-1", source)); } /** @@ -1367,11 +1375,11 @@ public class StringUtil /** * Helper function for {@link #md5hex} and {@link #sha1hex}. */ - protected static String digest (String codec, String source) + protected static byte[] digest (String codec, String source) { try { MessageDigest digest = MessageDigest.getInstance(codec); - return hexlate(digest.digest(source.getBytes())); + return digest.digest(source.getBytes()); } catch (NoSuchAlgorithmException nsae) { throw new RuntimeException(codec + " codec not available"); }