Login
...or Sign up
Home
Search
Search Code Snippets
Search People
Hash MD5 with Java
public static String encryptMD5(String code){ try{ MessageDigest md = MessageDigest.getInstance("MD5"); byte[] input = code.getBytes(); //"UTF8"); input=md.digest(input); code = toHexadecimal(input); //new String(input,"UTF8"); return code; }catch(Exception e){ return code; } } private static String toHexadecimal(byte[] datos) { String resultado=""; ByteArrayInputStream input = new ByteArrayInputStream(datos); String cadAux; boolean ult0=false; int leido = input.read(); while(leido != -1) { cadAux = Integer.toHexString(leido); if(cadAux.length() < 2){ //Hay que aÒadir un 0 resultado += "0"; if(cadAux.length() == 0) ult0=true; }else{ ult0=false;} resultado += cadAux; leido = input.read(); } if(ult0)//quitamos el 0 si es un caracter aislado resultado= resultado.substring(0, resultado.length()-2)+resultado.charAt(resultado.length()-1); return resultado; } }
Score: 0/10
Would you like to comment?
Sign up
for a free account or
sign in
(if you are already a member).
URL:
Embed:
Uploaded on 3/21/2008 8:28:10 AM
by
cara
Programming Language:
Java
Tags:
hash
java
md5
Viewed 1090 times
Help
Help by email
What is Naslu?
|
About Naslu
|
Contact
|
Terms of Use
|
Downloads
|
Webprogramacion.com
|
Blog
|
Top
Links
Select language:
Español
|
English
© 2009 naslu.com