Updated HashCalculator to add MD5 hashing in there

This commit is contained in:
Joshua Kissoon 2014-04-05 22:39:33 +05:30
parent 51de9cbc82
commit 33f9eea09f

View File

@ -12,6 +12,15 @@ import java.security.NoSuchAlgorithmException;
public class HashCalculator public class HashCalculator
{ {
/**
* Computes the SHA-1 Hash.
*
* @param toHash The string to hash
*
* @return byte[20] The hashed string
*
* @throws java.security.NoSuchAlgorithmException
*/
public static byte[] sha1Hash(String toHash) throws NoSuchAlgorithmException public static byte[] sha1Hash(String toHash) throws NoSuchAlgorithmException
{ {
/* Create a MessageDigest */ /* Create a MessageDigest */
@ -23,4 +32,25 @@ public class HashCalculator
/* Get the hashed bytes */ /* Get the hashed bytes */
return md.digest(); return md.digest();
} }
/**
* Computes the MD5 Hash.
*
* @param toHash The string to hash
*
* @return byte[16] The hashed string
*
* @throws java.security.NoSuchAlgorithmException
*/
public byte[] md5Hash(String toHash) throws NoSuchAlgorithmException
{
/* Create a MessageDigest */
MessageDigest md = MessageDigest.getInstance("MD5");
/* Add password bytes to digest */
md.update(toHash.getBytes());
/* Get the hashed bytes */
return md.digest();
}
} }