split out md5Sum for use in i2ptunnel

This commit is contained in:
zzz
2012-10-15 13:57:09 +00:00
parent 977cdee046
commit 50cb427377

View File

@ -161,14 +161,28 @@ public class PasswordManager {
*/
public static String md5Hex(String subrealm, String user, String pw) {
String fullpw = user + ':' + subrealm + ':' + pw;
try {
byte[] data = fullpw.getBytes("ISO-8859-1");
byte[] sum = md5Sum(data);
if (sum != null)
// adds leading zeros if necessary
return DataHelper.toString(sum);
} catch (UnsupportedEncodingException uee) {}
return null;
}
/**
* Standard MD5 checksum
*
* @param data non-null
* @return 16 bytes, or null on error
*/
public static byte[] md5Sum(byte[] data) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(fullpw.getBytes("ISO-8859-1"));
// adds leading zeros if necessary
return DataHelper.toString(md.digest());
} catch (UnsupportedEncodingException uee) {
} catch (NoSuchAlgorithmException nsae) {
}
md.update(data);
return md.digest();
} catch (NoSuchAlgorithmException nsae) {}
return null;
}
}