I am working with some MD5 hashes that have been turned into number sequences using the methods shown below. Given the code and example hash below, how can I "reverse" the effect of the getString()
method and turn a numerical sequence back into an MD5 hash?
For example, encrypt("umadbro");
returns "1518918615824625494170109603025017352201241" because the MD5 hash is passed through the getString()
method. The MD5 hash for "umadbro" is 9759ba9ef6fe5eaa6d3c1efaad34c9f1. I need a method that takes a string of numbers modified by the getString()
method and converts it into its MD5 hash. For example: reverseMethod("1518918615824625494170109603025017352201241");
should output "9759ba9ef6fe5eaa6d3c1efaad34c9f1" (The input parameter is the modified string of numbers and the output is the MD5 hash of the original string). NOTE: I am not looking for a method to crack the MD5 hash. I only need a method that reverses the effect of the getString()
method shown below.
public String encrypt(String source)
{
try
{
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] bytes = md.digest(source.getBytes());
return getString(bytes);
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}
private String getString(byte[] bytes) //this takes an md5 hash and turns it into a string of numbers.
// How can I reverse the effect of this method?
{
StringBuffer sb = new StringBuffer();
for (int i = 0; i < bytes.length; i++)
{
byte b = bytes[i];
sb.append(0xFF & b);
}
return sb.toString();
}