importjava.util.*;importjava.io.*;importjava.security.*;classTesteMD5{privatestaticStringhexString(byte[]bytes){Formatterfm=newFormatter(newStringBuilder());for(inti=0;i<bytes.length;++i){fm.format("%02X",bytes[i]&0xFF);}returnfm.toString();}publicstaticStringcalcMD5(Stringstr){try{byte[]bytes=str.getBytes("UTF-8");MessageDigestmd=MessageDigest.getInstance("MD5");returnhexString(md.digest(bytes));}catch(UnsupportedEncodingExceptionex){// UTF-8 sempre está disponívelthrownewRuntimeException("Can't happen",ex);}catch(NoSuchAlgorithmExceptionex){// MD5 sempre está disponívelthrownewRuntimeException("Can't happen",ex);}}publicstaticvoidmain(String[]args){System.out.println(calcMD5("Jose Aparecido"));}}
T
Tecno-Java
Desculpe ressucitar o topico mas gostaria de saber para que serve o metodo de hexa?
Abraços
A
ACPF1986
Se eu me lembro bem, era para quando vc quisesse criptografar em hexa alguma string.
Exemplo: abc123 => A1B2C3E4F5