I am trying to calculate a hash based on a rounded value of the system time to allow me time to input the value on another device and check that it's the same hash. When I run the code, it shows me that localTime
variable has the same value but i get different values for the digest and can't figure out why.
public static String getTime()
{
String localTime = "";
Calendar cal = Calendar.getInstance();
long mins = cal.getTimeInMillis()/10000;
localTime = Long.toString(mins);
System.out.println(localTime);
byte [] digest = null;
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(localTime.getBytes());
digest = md.digest();
md.reset();
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return digest.toString();
}