http://paquesepas.wordpress.com/2008/07/09/md5-hexadecimal-hashing-en-java/
En resumen, el código final es este:
private static final char[] HEXADECIMAL = { '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
public String hash(String stringToHash) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] bytes = md.digest(stringToHash.getBytes());
StringBuilder sb = new StringBuilder(2 * bytes.length);
for (int i = 0; i < bytes.length; i++) {
int low = (int)(bytes[i] & 0x0f);
int high = (int)((bytes[i] & 0xf0) >> 4);
sb.append(HEXADECIMAL[high]);
sb.append(HEXADECIMAL[low]);
}
return sb.toString();
} catch (NoSuchAlgorithmException e) {
//exception handling goes here
return null;
}
}
La explicación de todo el código, está en el mismo blog del autor
0 comentarios:
Publicar un comentario en la entrada
Si quieres hacer una pregunta más específica, hazla en los foros que tenemos habilitados en LinkedIn
Ah! solo se permiten comentarios de usuarios registrados. Si tienes OpenID, bienvenido! Puedes obtener su OpenID, aquí: http://openid.net/