/**
*paramString:第三方android应用的包名
*/
public String getSign(Context context, String paramString) {
try{
Signature signature = getRawSignature(context, paramString);
if (signature ==null) {
Log.w("getSign","signs is null");
return "";
}
return encode(signature.toCharsString());
}catch (Exception e){
e.printStackTrace();
}
return "";
}
private Signature getRawSignature(Context paramContext, String paramString) {
if ((paramString ==null) || (paramString.length() ==0)) {
return null;
}
PackageManager localPackageManager = paramContext.getPackageManager();
PackageInfo localPackageInfo;
try {
localPackageInfo = localPackageManager.getPackageInfo(paramString,GET_SIGNATURES);
if (localPackageInfo ==null) {
return null;
}
}catch (PackageManager.NameNotFoundException localNameNotFoundException) {
return null;
}
return localPackageInfo.signatures[0];
}
private static String encode(String origin) {
try {
String resultString =new String(origin);
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] byt = resultString.getBytes();
byte[] byt2 = md.digest(byt);
resultString =byteArrayToHexString(byt2);
return resultString;
}catch (Exception e) {
e.printStackTrace();
}
return origin;
}
private static String byteArrayToHexString(byte b[]) {
StringBuilder resultSb =new StringBuilder();
for (int i =0; i < b.length; i++) {
resultSb.append(byteToHexString(b[i]));
}
return resultSb.toString();
}
private static String byteToHexString(byte b) {
int n = b;
if (n <0)
n +=256;
int d1 = n /16;
int d2 = n %16;
return hexDigits[d1] +hexDigits[d2];
}