Java 类android.content.pm.Signature 实例源码

项目:android-security    文件:SignatureUtils.java   
public static boolean checkSignature(Context context) {
    try {
        PackageInfo packageInfo = context.getPackageManager()
                .getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES);
        for (Signature signature : packageInfo.signatures) {
            MessageDigest sha = MessageDigest.getInstance("SHA");
            sha.update(signature.toByteArray());
            final String currentSignature = Base64.encodeToString(sha.digest(), Base64.DEFAULT);
            if (SIGNATURE.equals(currentSignature)) {
                return true;
            }
        }
    } catch (Exception e) {
        Log.e(TAG, "Failed to check signature", e);
    }

    return false;
}
项目:mobile-store    文件:InstalledAppTestUtils.java   
public static void install(Context context,
                           String packageName,
                           int versionCode, String versionName,
                           @Nullable String signingCert,
                           @Nullable String hash) {
    PackageInfo info = new PackageInfo();
    info.packageName = packageName;
    info.versionCode = versionCode;
    info.versionName = versionName;
    info.applicationInfo = new ApplicationInfo();
    info.applicationInfo.publicSourceDir = "/tmp/mock-location";
    if (signingCert != null) {
        info.signatures = new Signature[]{new Signature(signingCert)};
    }

    String hashType = "sha256";
    if (hash == null) {
        hash = "00112233445566778899aabbccddeeff";
    }

    InstalledAppProviderService.insertAppIntoDb(context, info, hashType, hash);
}
项目:Nird2    文件:ScreenFilterMonitorImpl.java   
private boolean isPlayServices(String pkg) {
    if (!PLAY_SERVICES_PACKAGE.equals(pkg)) return false;
    try {
        PackageInfo sigs = pm.getPackageInfo(pkg, GET_SIGNATURES);
        // The genuine Play Services app should have a single signature
        Signature[] signatures = sigs.signatures;
        if (signatures == null || signatures.length != 1) return false;
        // Extract the public key from the signature
        CertificateFactory certFactory =
                CertificateFactory.getInstance("X509");
        byte[] signatureBytes = signatures[0].toByteArray();
        InputStream in = new ByteArrayInputStream(signatureBytes);
        X509Certificate cert =
                (X509Certificate) certFactory.generateCertificate(in);
        byte[] publicKeyBytes = cert.getPublicKey().getEncoded();
        String publicKey = StringUtils.toHexString(publicKeyBytes);
        return PLAY_SERVICES_PUBLIC_KEY.equals(publicKey);
    } catch (NameNotFoundException | CertificateException e) {
        if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
        return false;
    }
}
项目:stynico    文件:Update.java   
private void setViewPager()
  {
final String packname = getPackageName();
try
{
    PackageInfo packageInfo = getPackageManager().getPackageInfo(packname, PackageManager.GET_SIGNATURES);
    Signature[] signs = packageInfo.signatures;
    Signature sign = signs[0];
    int code = sign.hashCode();
    if (code != 312960342)
    {       
        ti();

    }
    else
    {
        //
    }
}
catch (PackageManager.NameNotFoundException e)
{}
      fragments = new ArrayList<Fragment>();
      viewPager.setAdapter(viewPagerAdapter);
      mTabLayout.setupWithViewPager(viewPager);
      mTabLayout.setTabsFromPagerAdapter(viewPagerAdapter);
  }
项目:AndroidBackendlessChat    文件:Facebook.java   
/**
 * Query the signature for the application that would be invoked by the
 * given intent and verify that it matches the FB application's signature.
 * 
 * @param context
 * @param packageName
 * @return true if the app's signature matches the expected signature.
 */
private boolean validateAppSignatureForPackage(Context context, String packageName) {

    PackageInfo packageInfo;
    try {
        packageInfo = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
    } catch (NameNotFoundException e) {
        return false;
    }

    for (Signature signature : packageInfo.signatures) {
        if (signature.toCharsString().equals(FB_APP_SIGNATURE)) {
            return true;
        }
    }
    return false;
}
项目:Nird2    文件:ScreenFilterMonitorImpl.java   
private boolean isPlayServices(String pkg) {
    if (!PLAY_SERVICES_PACKAGE.equals(pkg)) return false;
    try {
        PackageInfo sigs = pm.getPackageInfo(pkg, GET_SIGNATURES);
        // The genuine Play Services app should have a single signature
        Signature[] signatures = sigs.signatures;
        if (signatures == null || signatures.length != 1) return false;
        // Extract the public key from the signature
        CertificateFactory certFactory =
                CertificateFactory.getInstance("X509");
        byte[] signatureBytes = signatures[0].toByteArray();
        InputStream in = new ByteArrayInputStream(signatureBytes);
        X509Certificate cert =
                (X509Certificate) certFactory.generateCertificate(in);
        byte[] publicKeyBytes = cert.getPublicKey().getEncoded();
        String publicKey = StringUtils.toHexString(publicKeyBytes);
        return PLAY_SERVICES_PUBLIC_KEY.equals(publicKey);
    } catch (NameNotFoundException | CertificateException e) {
        if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
        return false;
    }
}
项目:MiPushFramework    文件:MiuiPushActivateService.java   
private boolean verifySignatures(String str) {
    try {
        PackageInfo packageInfo = getPackageManager().getPackageInfo(str, PackageManager.GET_SIGNATURES);
        if (packageInfo.signatures != null) {
            for (Object obj : packageInfo.signatures) {
                for (Signature equals : MIUI_PLATFORM_SIGNATURES) {
                    if (equals.equals(obj)) {
                        return true;
                    }
                }
            }
        }
    } catch (NameNotFoundException e) {
    }
    return false;
}
项目:OkSign    文件:MainActivity.java   
private void updateSignatures(String packageName) {
  List<PackageInfo> list =
      getPackageManager().getInstalledPackages(PackageManager.GET_SIGNATURES);
  PackageInfo packageInfo = null;
  for (PackageInfo info : list) {
    if (info.packageName.equals(packageName)) {
      packageInfo = info;
      break;
    }
  }
  if (packageInfo == null) {
    packageView.setError("Cannot find package.");
    return;
  }
  Signature[] signs = packageInfo.signatures;
  signatures.clear();
  for (Signature sign : signs) {
    ByteString byteString = ByteString.of(sign.toByteArray());
    signatures.add(byteString.md5().hex());
  }
  signaturesView.getAdapter().notifyDataSetChanged();
}
项目:chat-sdk-android-push-firebase    文件:Facebook.java   
/**
 * Query the signature for the application that would be invoked by the
 * given intent and verify that it matches the FB application's signature.
 * 
 * @param context
 * @param packageName
 * @return true if the app's signature matches the expected signature.
 */
private boolean validateAppSignatureForPackage(Context context, String packageName) {

    PackageInfo packageInfo;
    try {
        packageInfo = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
    } catch (NameNotFoundException e) {
        return false;
    }

    for (Signature signature : packageInfo.signatures) {
        if (signature.toCharsString().equals(FB_APP_SIGNATURE)) {
            return true;
        }
    }
    return false;
}
项目:letv    文件:IApkManagerImpl.java   
public PackageInfo getPackageInfo(String packageName, int flags) throws RemoteException {
    waitForReadyInner();
    try {
        String pkg = getAndCheckCallingPkg(packageName);
        if (pkg != null) {
            enforcePluginFileExists();
            PluginPackageParser parser = (PluginPackageParser) this.mPluginCache.get(pkg);
            if (parser != null) {
                PackageInfo packageInfo = parser.getPackageInfo(flags);
                if (packageInfo == null || (flags & 64) == 0 || packageInfo.signatures != null) {
                    return packageInfo;
                }
                packageInfo.signatures = (Signature[]) this.mSignatureCache.get(packageName);
                return packageInfo;
            }
        }
    } catch (Exception e) {
        handleException(e);
    }
    return null;
}
项目:letv    文件:IApkManagerImpl.java   
private void saveSignatures(PackageInfo pkgInfo) {
    JLog.log("plugin", "保存签名信息: " + pkgInfo.signatures);
    if (pkgInfo != null && pkgInfo.signatures != null) {
        int i = 0;
        Signature[] signatureArr = pkgInfo.signatures;
        int length = signatureArr.length;
        int i2 = 0;
        while (i2 < length) {
            Signature signature = signatureArr[i2];
            File file = new File(PluginDirHelper.getPluginSignatureFile(this.mContext, pkgInfo.packageName, i));
            try {
                Utils.writeToFile(file, signature.toByteArray());
                JLog.log("plugin", "保存签名信息 包名=" + pkgInfo.packageName + ",i=" + i + ", 签名md5=" + Utils.md5(signature.toByteArray()));
                i++;
                i2++;
            } catch (Exception e) {
                JLog.log("plugin", "保存签名信息失败 e=" + e.getMessage());
                file.delete();
                Utils.deleteDir(PluginDirHelper.getPluginSignatureDir(this.mContext, pkgInfo.packageName));
                return;
            }
        }
    }
}
项目:letv    文件:IApkManagerImpl.java   
private Signature[] readSignatures(String packageName) {
    List<String> fils = PluginDirHelper.getPluginSignatureFiles(this.mContext, packageName);
    List<Signature> signatures = new ArrayList(fils.size());
    int i = 0;
    for (String file : fils) {
        try {
            byte[] data = Utils.readFromFile(new File(file));
            if (data != null) {
                Signature sin = new Signature(data);
                signatures.add(sin);
                JLog.log("plugin", "读取签名信息 包名=" + packageName + ",i=" + i + ",签名md5=" + Utils.md5(sin.toByteArray()));
                i++;
            } else {
                JLog.log("plugin", "读取签名信息失败 i=" + i);
                return null;
            }
        } catch (Exception e) {
            JLog.log("plugin", "读取签名信息失败 e=" + e.getMessage());
            return null;
        }
    }
    return (Signature[]) signatures.toArray(new Signature[signatures.size()]);
}
项目:letv    文件:IApkManagerImpl.java   
public int checkSignatures(String pkg1, String pkg2) throws RemoteException {
    PackageManager pm = this.mContext.getPackageManager();
    Signature[] signatureArr = new Signature[0];
    try {
        signatureArr = getSignature(pkg1, pm);
        Signature[] signatureArr2 = new Signature[0];
        try {
            signatureArr2 = getSignature(pkg2, pm);
            boolean pkg1Signed = signatureArr != null && signatureArr.length > 0;
            boolean pkg2Signed = signatureArr2 != null && signatureArr2.length > 0;
            if (!pkg1Signed && !pkg2Signed) {
                return 1;
            }
            if (!pkg1Signed && pkg2Signed) {
                return -1;
            }
            if (pkg1Signed && !pkg2Signed) {
                return -2;
            }
            if (signatureArr.length != signatureArr2.length) {
                return -3;
            }
            for (int i = 0; i < signatureArr.length; i++) {
                if (!Arrays.equals(signatureArr[i].toByteArray(), signatureArr2[i].toByteArray())) {
                    return -3;
                }
            }
            return 0;
        } catch (NameNotFoundException e) {
            return -4;
        }
    } catch (NameNotFoundException e2) {
        return -4;
    }
}
项目:letv    文件:FacebookSdk.java   
public static String getApplicationSignature(Context context) {
    Validate.sdkInitialized();
    if (context == null) {
        return null;
    }
    PackageManager packageManager = context.getPackageManager();
    if (packageManager == null) {
        return null;
    }
    try {
        PackageInfo pInfo = packageManager.getPackageInfo(context.getPackageName(), 64);
        Signature[] signatures = pInfo.signatures;
        if (signatures == null || signatures.length == 0) {
            return null;
        }
        try {
            MessageDigest md = MessageDigest.getInstance(CommonUtils.SHA1_INSTANCE);
            md.update(pInfo.signatures[0].toByteArray());
            return Base64.encodeToString(md.digest(), 9);
        } catch (NoSuchAlgorithmException e) {
            return null;
        }
    } catch (NameNotFoundException e2) {
        return null;
    }
}
项目:letv    文件:a.java   
public static boolean g(Context context) {
    boolean z = false;
    try {
        Signature[] signatureArr = context.getPackageManager().getPackageInfo(context.getPackageName(), 64).signatures;
        CertificateFactory instance = CertificateFactory.getInstance(z[16]);
        int i = 0;
        while (i < signatureArr.length) {
            boolean equals = ((X509Certificate) instance.generateCertificate(new ByteArrayInputStream(signatureArr[i].toByteArray()))).getSubjectX500Principal().equals(c);
            if (equals) {
                return equals;
            }
            i++;
            z = equals;
        }
        return z;
    } catch (NameNotFoundException e) {
        return false;
    } catch (Exception e2) {
        return false;
    }
}
项目:amap    文件:MIP_SystemUtils.java   
/**
 * <一句话功能简述> 获取签名名
 * 
 * @Description<功能详细描述>
 * 
 * @param packageName
 * @return
 * @LastModifiedDate:2015-8-31
 * @author rqj
 * @EditHistory:<修改内容><修改人>
 */
public static String getRelease(String packageName)
{
    StringBuilder builder = new StringBuilder();
    try
    {
        PackageManager pm = GlobalState.getInstance().getPackageManager();
        PackageInfo pi = pm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
        for (Signature sig : pi.signatures)
        {
            builder.append(sig.toCharsString());
        }
        return builder.toString();
    }
    catch (Exception e)
    {
        LogUtil.e(e);
    }

    return "";
}
项目:FeedFire    文件:FacebookSign.java   
public static void keyHash(Context context){

        // Add code to print out the key hash
        try {
            PackageInfo info = context.getPackageManager().getPackageInfo(
                    "barreto.alessandro.feedlist",
                    PackageManager.GET_SIGNATURES);
            for (Signature signature : info.signatures) {
                MessageDigest md = MessageDigest.getInstance("SHA");
                md.update(signature.toByteArray());
                Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
            }
        } catch (PackageManager.NameNotFoundException | NoSuchAlgorithmException ignored) {
            Log.e("Facebook",ignored.getMessage());
        }

    }
项目:SmartChart    文件:AppUtils.java   
/**
 * 检测当前应用是否是Debug版本
 *
 * @param ctx
 * @return
 */
public static boolean isDebuggable(Context ctx) {
    boolean debuggable = false;
    try {
        PackageInfo pinfo = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), PackageManager.GET_SIGNATURES);
        Signature signatures[] = pinfo.signatures;
        for (Signature signature : signatures) {
            CertificateFactory cf = CertificateFactory.getInstance("X.509");
            ByteArrayInputStream stream = new ByteArrayInputStream(signature.toByteArray());
            X509Certificate cert = (X509Certificate) cf
                    .generateCertificate(stream);
            debuggable = cert.getSubjectX500Principal().equals(DEBUG_DN);
            if (debuggable)
                break;
        }

    } catch (NameNotFoundException | CertificateException e) {
    }
    return debuggable;
}
项目:SecuritySample    文件:Utils.java   
/**
 * Gets the encoded representation of the first signing certificated used to sign current APK
 *
 * @param ctx
 * @return
 */
private static byte[] getSigningKeyCertificate(Context ctx) {
    try {
        PackageManager pm = ctx.getPackageManager();
        String packageName = ctx.getPackageName();
        int flags = PackageManager.GET_SIGNATURES;
        PackageInfo packageInfo = pm.getPackageInfo(packageName, flags);
        Signature[] signatures = packageInfo.signatures;

        if (signatures != null && signatures.length >= 1) {
            //takes just the first signature, TODO: handle multi signed apks
            byte[] cert = signatures[0].toByteArray();
            InputStream input = new ByteArrayInputStream(cert);
            CertificateFactory cf = CertificateFactory.getInstance("X509");
            X509Certificate c = (X509Certificate) cf.generateCertificate(input);
            return c.getEncoded();
        }
    } catch (Exception e) {
        Log.w(TAG, e);
    }
    return null;
}
项目:VirtualHook    文件:PackageParserEx.java   
public static void readSignature(VPackage pkg) {
    File signatureFile = VEnvironment.getSignatureFile(pkg.packageName);
    if (!signatureFile.exists()) {
        return;
    }
    Parcel p = Parcel.obtain();
    try {
        FileInputStream fis = new FileInputStream(signatureFile);
        byte[] bytes = FileUtils.toByteArray(fis);
        fis.close();
        p.unmarshall(bytes, 0, bytes.length);
        p.setDataPosition(0);
        pkg.mSignatures = p.createTypedArray(Signature.CREATOR);
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        p.recycle();
    }
}
项目:Brevent    文件:BreventApplication.java   
public static BigInteger getSignature(Context context) {
    if (modulus != null) {
        return modulus;
    }
    Signature[] signatures = BreventActivity.getSignatures(context.getPackageManager(),
            BuildConfig.APPLICATION_ID);
    if (signatures == null || signatures.length != 1) {
        return null;
    }
    try {
        final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
        final ByteArrayInputStream bais = new ByteArrayInputStream(signatures[0].toByteArray());
        final Certificate cert = certFactory.generateCertificate(bais);
        modulus = ((RSAPublicKey) cert.getPublicKey()).getModulus();
    } catch (GeneralSecurityException e) {
        UILog.w("Can't get signature", e);
        return null;
    }
    return modulus;
}
项目:AirQuickUtils    文件:AirSystem.java   
/**
 * Is this APK signed or is it a Debug build?
 *
 * @return true if it is not signed
 */
public static boolean isDebuggable() {
    boolean debuggable = false;
    Context ctx = AirQuickUtils.getContext();

    try {
        PackageInfo pinfo = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), PackageManager.GET_SIGNATURES);
        Signature signatures[] = pinfo.signatures;

        CertificateFactory cf = CertificateFactory.getInstance("X.509");

        for (int i = 0; i < signatures.length; i++) {
            ByteArrayInputStream stream = new ByteArrayInputStream(signatures[i].toByteArray());
            X509Certificate cert = (X509Certificate) cf.generateCertificate(stream);
            debuggable = cert.getSubjectX500Principal().equals(DEBUG_DN);
            if (debuggable)
                break;
        }
    } catch (NameNotFoundException | CertificateException ignored) {
    }
    return debuggable;
}
项目:OpenYOLO-Android    文件:TargetAndroidAssetStatementLoader.java   
/**
 * Check if the {@link PackageInfo} app contains the specified cert fingerprint.
 *
 * @param packageInfo PackageInfo (retrieved with
 * {@link PackageManager#GET_SIGNATURES}
 * @param certFingerprint Hex, SHA-256 of the app signature (no dots)
 *
 * @return Whether the specified app contains the cert fingerprint
 */
static boolean containsFingerprint(@NonNull PackageInfo packageInfo,
            @NonNull final String certFingerprint) {

    require(packageInfo, notNullValue());
    require(!TextUtils.isEmpty(certFingerprint), "certFingerprint must not be null or empty");

    final String paramFingerprint = certFingerprint.replaceAll(":", "");

    for (Signature signature : packageInfo.signatures) {
        String fingerprint = toHex(sha256(signature.toByteArray()));
        if (fingerprint.equals(paramFingerprint)) {
            return true;
        }
    }
    return false;
}
项目:android-banklink    文件:RequestTest.java   
@SuppressWarnings("WrongConstant")
private void installApp(@NonNull String packageName,
                        int versionCode,
                        @NonNull Signature signature) {
  final ResolveInfo resolveInfo = new ResolveInfo();
  resolveInfo.activityInfo = new ActivityInfo();
  resolveInfo.activityInfo.packageName = packageName;
  banklinkActivities.add(resolveInfo);
  final PackageInfo packageInfo = new PackageInfo();
  packageInfo.versionCode = versionCode;
  packageInfo.packageName = packageName;
  packageInfo.signatures = new Signature[1];
  packageInfo.signatures[0] = signature;
  try {
    when(context.getPackageManager().getPackageInfo(eq(packageName), anyInt()))
        .thenReturn(packageInfo);
  } catch (PackageManager.NameNotFoundException e) {
    throw new RuntimeException(e);
  }
}
项目:DroidPlugin    文件:IPluginManagerImpl.java   
private void saveSignatures(PackageInfo pkgInfo) {
    if (pkgInfo != null && pkgInfo.signatures != null) {
        int i = 0;
        for (Signature signature : pkgInfo.signatures) {
            File file = new File(PluginDirHelper.getPluginSignatureFile(mContext, pkgInfo.packageName, i));
            try {
                Utils.writeToFile(file, signature.toByteArray());
                Log.i(TAG, "Save %s signature of %s,md5=%s", pkgInfo.packageName, i, Utils.md5(signature.toByteArray()));
            } catch (Exception e) {
                e.printStackTrace();
                Log.w(TAG, "Save signatures fail", e);
                file.delete();
                Utils.deleteDir(PluginDirHelper.getPluginSignatureDir(mContext, pkgInfo.packageName));
                break;
            }
            i++;
        }
    }
}
项目:DroidPlugin    文件:IPluginManagerImpl.java   
private Signature[] readSignatures(String packageName) {
    List<String> fils = PluginDirHelper.getPluginSignatureFiles(mContext, packageName);
    List<Signature> signatures = new ArrayList<Signature>(fils.size());
    int i = 0;
    for (String file : fils) {
        try {
            byte[] data = Utils.readFromFile(new File(file));
            if (data != null) {
                Signature sin = new Signature(data);
                signatures.add(sin);
                Log.i(TAG, "Read %s signature of %s,md5=%s", packageName, i, Utils.md5(sin.toByteArray()));
            } else {
                Log.i(TAG, "Read %s signature of %s FAIL", packageName, i);
                return null;
            }
            i++;
        } catch (Exception e) {
            Log.i(TAG, "Read %s signature of %s FAIL", e, packageName, i);
            return null;
        }
    }
    return signatures.toArray(new Signature[signatures.size()]);
}
项目:android-study    文件:SystemApiFragment.java   
private void init() {
  //mRoot.setText("是否Root: " + AppUtils.isAppRoot());
  mPackageName.setText("App包名: " + AppUtils.getAppPackageName());
  mAppName.setText("App名称: " + AppUtils.getAppName());
  mAppIcon.setImageDrawable(AppUtils.getAppIcon());
  mAppPath.setText("App路径: " + AppUtils.getAppPath());
  mAppVersion.setText("App版本: " + AppUtils.getAppVersionName());
  mAppCode.setText("App版本码: " + AppUtils.getAppVersionCode());
  mAppSystemApp.setText("是否是系统App: " + AppUtils.isSystemApp());
  mAppDebug.setText("是否是Debug版: " + AppUtils.isAppDebug());
  mAppSignature.setText("App签名: " + getAppSignature());
  mAppSha1.setText("应用签名的SHA1值: " + AppUtils.getAppSignatureSHA1());
  Signature[] signatures = AppUtils.getAppSignature();
  String md5 = EncryptUtils.encryptMD5ToString(signatures[0].toByteArray())
      .replaceAll("(?<=[0-9A-F]{2})[0-9A-F]{2}", ":$0");
  mAppMd5.setText("应用签名的SHA1值: " + md5);
}
项目:boohee_v5.6    文件:WXApiImplComm.java   
public static boolean validateAppSignature(Context context, Signature[] signatureArr, boolean
        z) {
    if (z) {
        for (Signature toCharsString : signatureArr) {
            String toLowerCase = toCharsString.toCharsString().toLowerCase();
            a.d(TAG, "check signature:" + toLowerCase);
            if (toLowerCase.equals(WX_APP_SIGNATURE)) {
                a.d(TAG, "pass");
                return true;
            }
        }
        return false;
    }
    a.d(TAG, "ignore wechat app signature validation");
    return true;
}
项目:boohee_v5.6    文件:SinaSsoHandler.java   
private boolean validateAppSignatureForIntent(Context context, Intent intent) {
    PackageManager pm = context.getPackageManager();
    ResolveInfo resolveInfo = pm.resolveActivity(intent, 0);
    if (resolveInfo == null) {
        return false;
    }
    try {
        for (Signature signature : pm.getPackageInfo(resolveInfo.activityInfo.packageName,
                64).signatures) {
            if (WEIBO_SIGNATURE.equals(signature.toCharsString())) {
                return true;
            }
        }
        return false;
    } catch (NameNotFoundException e) {
        return false;
    }
}
项目:boohee_v5.6    文件:h.java   
private boolean b(Intent intent) {
    ResolveInfo resolveActivity = this.a.getContext().getPackageManager().resolveActivity(intent, 0);
    if (resolveActivity == null) {
        return false;
    }
    try {
        for (Signature toCharsString : this.a.getContext().getPackageManager().getPackageInfo(resolveActivity.activityInfo.packageName, 64).signatures) {
            if ("30820295308201fea00302010202044b4ef1bf300d06092a864886f70d010105050030818d310b300906035504061302434e3110300e060355040813074265694a696e673110300e060355040713074265694a696e67312c302a060355040a132353696e612e436f6d20546563686e6f6c6f677920284368696e612920436f2e204c7464312c302a060355040b132353696e612e436f6d20546563686e6f6c6f677920284368696e612920436f2e204c74643020170d3130303131343130323831355a180f32303630303130323130323831355a30818d310b300906035504061302434e3110300e060355040813074265694a696e673110300e060355040713074265694a696e67312c302a060355040a132353696e612e436f6d20546563686e6f6c6f677920284368696e612920436f2e204c7464312c302a060355040b132353696e612e436f6d20546563686e6f6c6f677920284368696e612920436f2e204c746430819f300d06092a864886f70d010101050003818d00308189028181009d367115bc206c86c237bb56c8e9033111889b5691f051b28d1aa8e42b66b7413657635b44786ea7e85d451a12a82a331fced99c48717922170b7fc9bc1040753c0d38b4cf2b22094b1df7c55705b0989441e75913a1a8bd2bc591aa729a1013c277c01c98cbec7da5ad7778b2fad62b85ac29ca28ced588638c98d6b7df5a130203010001300d06092a864886f70d0101050500038181000ad4b4c4dec800bd8fd2991adfd70676fce8ba9692ae50475f60ec468d1b758a665e961a3aedbece9fd4d7ce9295cd83f5f19dc441a065689d9820faedbb7c4a4c4635f5ba1293f6da4b72ed32fb8795f736a20c95cda776402099054fccefb4a1a558664ab8d637288feceba9508aa907fc1fe2b1ae5a0dec954ed831c0bea4".equals(toCharsString.toCharsString())) {
                return true;
            }
        }
        return false;
    } catch (NameNotFoundException e) {
        return false;
    }
}
项目:android-AutofillFramework    文件:SecurityHelper.java   
/**
 * Gets the fingerprint of the signed certificate of a package.
 */
public static String getFingerprint(Context context, String packageName) throws Exception {
    PackageManager pm = context.getPackageManager();
    PackageInfo packageInfo = pm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
    Signature[] signatures = packageInfo.signatures;
    if (signatures.length != 1) {
        throw new SecurityException(packageName + " has " + signatures.length + " signatures");
    }
    byte[] cert = signatures[0].toByteArray();
    try (InputStream input = new ByteArrayInputStream(cert)) {
        CertificateFactory factory = CertificateFactory.getInstance("X509");
        X509Certificate x509 = (X509Certificate) factory.generateCertificate(input);
        MessageDigest md = MessageDigest.getInstance("SHA256");
        byte[] publicKey = md.digest(x509.getEncoded());
        return toHexFormat(publicKey);
    }
}
项目:TPlayer    文件:PackageParserEx.java   
public static void readSignature(VPackage pkg) {
    File signatureFile = VEnvironment.getSignatureFile(pkg.packageName);
    if (!signatureFile.exists()) {
        return;
    }
    Parcel p = Parcel.obtain();
    try {
        FileInputStream fis = new FileInputStream(signatureFile);
        byte[] bytes = FileUtils.toByteArray(fis);
        fis.close();
        p.unmarshall(bytes, 0, bytes.length);
        p.setDataPosition(0);
        pkg.mSignatures = p.createTypedArray(Signature.CREATOR);
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        p.recycle();
    }
}
项目:container    文件:VPackageManagerService.java   
@Override
public PackageInfo getPackageInfo(String packageName, int flags, int userId) {
    synchronized (mPackages) {
        PackageParser.Package pkg = mPackages.get(packageName);
        if (pkg != null) {
            AppSetting setting = (AppSetting) pkg.mExtras;
            if ((flags & PackageManager.GET_SIGNATURES) != 0 && pkg.mSignatures == null) {
                if (pkg.mAppMetaData != null && pkg.mAppMetaData.containsKey(Constants.FEATURE_FAKE_SIGNATURE)) {
                    String sig = pkg.mAppMetaData.getString("fake-signature");
                    if (sig != null) {
                        pkg.mSignatures = new Signature[] {new Signature(sig)};
                    }
                } else {
                    PackageParserCompat.collectCertificates(setting.parser, pkg, PackageParser.PARSE_IS_SYSTEM);
                }
            }
            PackageInfo packageInfo = PackageParserCompat.generatePackageInfo(pkg, flags,
                    getFirstInstallTime(pkg), getLastInstallTime(pkg));
            if (packageInfo != null) {
                ComponentFixer.fixApplicationInfo(setting, packageInfo.applicationInfo, userId);
                return packageInfo;
            }
        }
    }
    return null;
}
项目:android-project-gallery    文件:ApkSignUtils.java   
/**
 * 返回指定算法对应的指纹信息
 * 
 * @param context
 * @param algorithm MD5 or SHA1
 * @return
 */
private static String getFingerprint(Context context, String algorithm) {
    try {
        String packageName = context.getApplicationContext().getApplicationInfo().packageName;
        PackageInfo packageInfo = context.getPackageManager().getPackageInfo(packageName,
                PackageManager.GET_SIGNATURES);
        Signature[] signs = packageInfo.signatures;
        MessageDigest md = MessageDigest.getInstance(algorithm);
        md.reset();
        md.update(signs[0].toByteArray());
        byte[] dataHash = md.digest();
        String hexString = bytes2HexString(dataHash);
        return hexString;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return null;
}
项目:android-project-gallery    文件:ApkSignUtils.java   
/**
 * 返回指定Apk文件的指纹信息
 * 
 * @param context
 * @param archiveFilePath
 * @param algorithm MD5 or SHA1
 * @return
 */
public static String getFingerprint(Context context, String archiveFilePath, String algorithm) {
    try {
        PackageInfo packageInfo = context.getPackageManager().getPackageArchiveInfo(archiveFilePath,
                PackageManager.GET_SIGNATURES);
        if (packageInfo == null) {
            return null;
        }
        Signature[] signs = packageInfo.signatures;
        MessageDigest md = MessageDigest.getInstance(algorithm);
        md.reset();
        md.update(signs[0].toByteArray());
        byte[] dataHash = md.digest();
        return bytes2HexString(dataHash);
    } catch (Exception e) {
        e.printStackTrace();
    }

    return null;
}
项目:Android-Practice    文件:MainActivity.java   
public static String getKeyHash(final Context context) {
    PackageInfo packageInfo = getPackageInfo(context, PackageManager.GET_SIGNATURES);
    if (packageInfo == null)
        return null;

    for (Signature signature : packageInfo.signatures) {
        try {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            return android.util.Base64.encodeToString(md.digest(), android.util.Base64.NO_WRAP);
        } catch (NoSuchAlgorithmException e) {
            //Log.w(TAG, "Unable to get MessageDigest. signature=" + signature, e);
        }
    }
    return null;
}
项目:https-github.com-hyb1996-NoRootScriptDroid    文件:DeveloperUtils.java   
public static String getSignature(Context context) {
    try {
        PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES);
        Signature[] signatures = packageInfo.signatures;
        StringBuilder builder = new StringBuilder();
        for (Signature signature : signatures) {
            builder.append(signature.toCharsString());
        }
        return builder.toString();
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return null;
}
项目:GitHub    文件:AppUtils.java   
/**
 * 获取App签名
 *
 * @param packageName 包名
 * @return App签名
 */
public static Signature[] getAppSignature(final String packageName) {
    if (isSpace(packageName)) return null;
    try {
        PackageManager pm = Utils.getApp().getPackageManager();
        @SuppressLint("PackageManagerGetSignatures")
        PackageInfo pi = pm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
        return pi == null ? null : pi.signatures;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
        return null;
    }
}
项目:ZeusHotfix    文件:Util.java   
/**
 * 获取某个已安装的包的签名信息
 *
 * @param packageName
 * @param context
 * @return
 * @throws Exception
 */
public static Signature[] getPackageSignature(String packageName, Context context) throws Exception {

    PackageInfo localPackageInfo = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
    if (localPackageInfo != null && localPackageInfo.signatures != null) {
        return localPackageInfo.signatures;
    }
    return getApkSignature(context.getPackageCodePath(), context);
}
项目:ZeusHotfix    文件:Util.java   
/**
 * 获取某个已安装的包的签名信息
 *
 * @param packageName
 * @param context
 * @return
 * @throws Exception
 */
public static Signature[] getPackageSignature(String packageName, Context context) throws Exception {

    PackageInfo localPackageInfo = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
    if (localPackageInfo != null && localPackageInfo.signatures != null) {
        return localPackageInfo.signatures;
    }
    return getApkSignature(context.getPackageCodePath(), context);
}