public void printSignatureMD5() {
try {
PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
Log.e("getMD5MessageDigest", getMD5MessageDigest(packageInfo.signatures[0].toByteArray()));
} catch (Exception e) {
e.printStackTrace();
}
}
public static String getMD5MessageDigest(byte[] bytes) {
StringBuffer md5StringBuffer = new StringBuffer();
try {
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
messageDigest.reset();
messageDigest.update(bytes);
byte[] digest = messageDigest.digest();
for (int i = 0; i < digest.length; i++) {
String hexString = Integer.toHexString(digest[i] & 0xff);
if (hexString.length() == 1)
md5StringBuffer.append("0");
md5StringBuffer.append(hexString);
}
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return md5StringBuffer.toString();
}
网友评论