Cómo calcular correctamente la suma de comprobación en Java
¿público?clase?MD5HashingExample?
{
público?static?void?main(String[]? args) throws?Exception
{
String?123456";
MessageDigest?md?=?MessageDigest.getInstance("MD5");
md.update(password.getBytes("UTF-8"));?
byte byteData[] = md.digest()
//convertir byte a hexadecimal; método de formato 1
StringBuffer sb = new StringBuffer();
for(int i = 0; i lt; byteData.length; i )?{ sb.append(Integer.toString ((byteData[i]?amp;?0xff)??0x100,?16).substring(1));
}
System.out.println("Digest( en?formato hexadecimal)::?") ? ?sb.toString());
//convertir?el?byte?a?formato?hexadecimal?2
StringBuffer?hexString?=?new?StringBuffer();
para ?(int?i=0;ilt;byteData.length;i )?{
String?hex= Integer.toHexString(0xff?amp;?byteData[i]);
? if(hex.length()==1)?hexString.append('0');
? hexString.append(hex);
}
System.out.println("Digest(en? formato hexadecimal)::?") ?hexString.toString( ));
}
}
}
}