mirror of
https://github.com/ChronosX88/KademliaDHT.git
synced 2024-11-22 10:12:19 +00:00
Updated HashCalculator to add MD5 hashing in there
This commit is contained in:
parent
51de9cbc82
commit
33f9eea09f
@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user