/**
* 获取应用签名
*
* @param context
* @param packageName
* @return
*/
public static String getRawSignatureStr(Context context, String packageName) {
try {
Signature[] signs = getRawSignature(context, packageName);
String signValidString = getSignValidString(signs[0].toByteArray());
return signValidString;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static Signature[] getRawSignature(Context context, String packageName) {
if (packageName == null || packageName.length() == 0) {
return null;
}
try {
PackageInfo info = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
if (info != null) {
return info.signatures;
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return null;
}
private static String getSignValidString(byte[] paramArrayOfByte) throws NoSuchAlgorithmException {
MessageDigest localMessageDigest = MessageDigest.getInstance("MD5");
localMessageDigest.update(paramArrayOfByte);
return toHexString(localMessageDigest.digest());
}
private static String toHexString(byte[] paramArrayOfByte) {
if (paramArrayOfByte == null) {
return null;
}
StringBuilder localStringBuilder = new StringBuilder(2 * paramArrayOfByte.length);
for (int i = 0; ; i++) {
if (i >= paramArrayOfByte.length) {
return localStringBuilder.toString();
}
String str = Integer.toString(0xFF & paramArrayOfByte[i], 16);
if (str.length() == 1) {
str = "0" + str;
}
localStringBuilder.append(str);
}
}
网友评论