获取apk文件的签名信息(未安装, 只是一个apk文件)

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

    /** 
     * get signature of an apk file 
     * this method will execute quit a long time, so it is suitable to call it in sub thread 
     * @param context 
     * @param apkFilePath 
     * @return signature , null if there is no signature , or apkFilePath is wrong 
     */  
    public static String getSignatureOfApk(Context context, String apkFilePath){  
        Log.i(TAG, "SignatureUtils.getSignatureOfApk");  
      
        if (TextUtils.isEmpty(apkFilePath)) return null;  
      
        PackageManager pm = context.getPackageManager();  
      
      
        PackageInfo pi = pm.getPackageArchiveInfo(apkFilePath, PackageManager.GET_SIGNATURES);  
        Signature[] signatures = pi.signatures;  
      
        if(signatures != null && signatures.length > 0){  
      
            String signature =  signatures[0].toCharsString();  
            Log.i(TAG, "Signature of " + apkFilePath + " is : " + signature);  
      
            return  signature;  
        }  
      
      
        return null;  
    }