diff --git a/src/kademlia/util/hashing/HashCalculator.java b/src/kademlia/util/hashing/HashCalculator.java index e94b196..0076cd0 100644 --- a/src/kademlia/util/hashing/HashCalculator.java +++ b/src/kademlia/util/hashing/HashCalculator.java @@ -33,6 +33,28 @@ public class HashCalculator return md.digest(); } + /** + * Computes the SHA-1 Hash using a Salt. + * + * @param toHash The string to hash + * @param salt A salt used to blind the hash + * + * @return byte[20] The hashed string + * + * @throws java.security.NoSuchAlgorithmException + */ + public static byte[] sha1Hash(String toHash, String salt) throws NoSuchAlgorithmException + { + /* Create a MessageDigest */ + MessageDigest md = MessageDigest.getInstance("SHA-1"); + + /* Add password bytes to digest */ + md.update(toHash.getBytes()); + + /* Get the hashed bytes */ + return md.digest(salt.getBytes()); + } + /** * Computes the MD5 Hash. * @@ -42,7 +64,7 @@ public class HashCalculator * * @throws java.security.NoSuchAlgorithmException */ - public byte[] md5Hash(String toHash) throws NoSuchAlgorithmException + public static byte[] md5Hash(String toHash) throws NoSuchAlgorithmException { /* Create a MessageDigest */ MessageDigest md = MessageDigest.getInstance("MD5"); @@ -53,4 +75,26 @@ public class HashCalculator /* Get the hashed bytes */ return md.digest(); } + + /** + * Computes the MD5 Hash using a salt. + * + * @param toHash The string to hash + * @param salt A salt used to blind the hash + * + * @return byte[16] The hashed string + * + * @throws java.security.NoSuchAlgorithmException + */ + public static byte[] md5Hash(String toHash, String salt) 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(salt.getBytes()); + } }