获取Android应用程序签名 2014-09-11- 2022-07-24这就是一个工具类,直接上代码了: 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687import java.security.MessageDigest;import android.content.Context;import android.content.pm.PackageInfo;import android.content.pm.PackageManager;import android.content.pm.Signature;import android.util.Log;/** * 签名工具类 * * */public class SignUtil { /** * 获取对应包名的应用的签名串 * * @param context * @param paramString * 应用程序包名 * @return */ public static String getSign(Context context, String paramString) { if (context == null) { throw new IllegalAccessError("Context is null!!!"); } Signature[] arrayOfSignature = getRawSignature(context, paramString); if ((arrayOfSignature == null) || (arrayOfSignature.length == 0)) { Log.d("SIGN", "signs is null"); return null; } int i = arrayOfSignature.length; if (i > 0) { return getMessageDigest(arrayOfSignature[0].toByteArray()); } return null; } private static Signature[] getRawSignature(Context paramContext, String paramString) { if ((paramString == null) || (paramString.length() == 0)) { Log.d("SIGN", "getSignature, packageName is null"); return null; } PackageManager localPackageManager = paramContext.getPackageManager(); PackageInfo localPackageInfo; try { localPackageInfo = localPackageManager.getPackageInfo(paramString, 64); if (localPackageInfo == null) { Log.d("SIGN", "info is null, packageName = " + paramString); return null; } } catch (PackageManager.NameNotFoundException localNameNotFoundException) { Log.d("SIGN", "NameNotFoundException"); return null; } return localPackageInfo.signatures; } private static final String getMessageDigest(byte[] paramArrayOfByte) { char[] arrayOfChar1 = { 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102 }; try { MessageDigest localMessageDigest = MessageDigest.getInstance("MD5"); localMessageDigest.update(paramArrayOfByte); byte[] arrayOfByte = localMessageDigest.digest(); int i = arrayOfByte.length; char[] arrayOfChar2 = new char[i * 2]; int j = 0; int k = 0; while (true) { if (j >= i) return new String(arrayOfChar2); int m = arrayOfByte[j]; int n = k + 1; arrayOfChar2[k] = arrayOfChar1[(0xF & m >>> 4)]; k = n + 1; arrayOfChar2[n] = arrayOfChar1[(m & 0xF)]; j++; } } catch (Exception localException) { } return null; }}我很可爱,请给我钱本文作者:Cat本文链接:https://szxiot.com/2014/09/11/get-android-apk-sign/版权声明:本博客所有文章除特别声明外,均默认采用 许可协议。