MD5

/** * Created by Xeis con k on 07/01/2015. */ public class MD5 { public static String hash(String string){ try{ //primero hacer el hash MessageDigest digest = MessageDigest.getInstance("MD5"); digest.update(string.getBytes()); byte[] messageDigest = digest.digest(); //luego convertirlo a cadena StringBuilder hexString = new StringBuilder(); for(int i=0; i<messageDigest.length; i++){ String hex = Integer.toHexString(0xFF & messageDigest[i]); while (hex.length() <2){ hex = "0"+hex; } hexString.append(hex); } return hexString.toString(); } catch (NoSuchAlgorithmException e){ e.printStackTrace(); } //en caso de fallo devolver cadena original eliminando caracteres no usables en url return string.replaceAll("[.:/,%?#&=]",""); } }
Metodo simple para generar hash MD5 de un String

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.