Andreoid MD5加密

MD5加密取16位:

MessageDigest messageDigest = null;


try {
messageDigest = MessageDigest.getInstance("MD5");
messageDigest.reset();
messageDigest.update(str.getBytes(“UTF-8”);
} catch (Exception e) {
Log.e("Error", e.getMessage());
}


byte[] byteArray = messageDigest.digest();


StringBuffer stringBuffer = new StringBuffer();


for (int i = 0; i < byteArray.length; i++) {
if (Integer.toHexString(0xFF & byteArray[i]).length() == 1) stringBuffer.append("0").append(Integer.toHexString(0xFF & byteArray[i]));
else stringBuffer.append(Integer.toHexString(0xFF & byteArray[i]));
}
// 16 byte
return stringBuffer.substring(8, 24).toString().toUpperCase();

你可能感兴趣的:(Andreoid MD5加密)