import java.
io.
*;
import java.
security.
*;
/**
* Quick MD5 tool.
* The intended use of this file is to be inserted into Oracle and referenced through PL/SQL
* but this can be used as a quick and easy way to generate a MD5 hash of a string
*
*@author jtaylor
*@created January 10, 2005
*/
public class stringMD5
{
/**
* Method used to convert byte array to string.
*
*@param array Byte Array you would like converted to string format
*@return String format of byte array
*/
private static String hex
(byte[] array
)
{
StringBuffer sb =
new StringBuffer();
for (int i =
0; i < array.
length; ++i
)
{
sb.
append(Integer.
toHexString((array
[i
] & 0xFF
) | 0x100
).
toUpperCase().
substring(1,
3));
}
return sb.
toString();
}
/**
* Static method to generate an MD5 hash from a string
*
*@param message String or message that you would like an MD5 hash of.
*@return MD5 has value of string
*/
public static String md5
(String message
)
{
try
{
MessageDigest md =
MessageDigest.
getInstance("MD5");
return hex
(md.
digest(message.
getBytes("CP1252")));
} catch (NoSuchAlgorithmException e
)
{
} catch (UnsupportedEncodingException e
)
{
}
return null;
}
}