当前位置: 首页>>代码示例>>Java>>正文


Java Signature类代码示例

本文整理汇总了Java中android.content.pm.Signature的典型用法代码示例。如果您正苦于以下问题:Java Signature类的具体用法?Java Signature怎么用?Java Signature使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Signature类属于android.content.pm包,在下文中一共展示了Signature类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkSignature

import android.content.pm.Signature; //导入依赖的package包/类
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;
}
 
开发者ID:rafaeltoledo,项目名称:android-security,代码行数:19,代码来源:SignatureUtils.java

示例2: getSigningKeyCertificate

import android.content.pm.Signature; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:Catherine22,项目名称:SecuritySample,代码行数:28,代码来源:Utils.java

示例3: setViewPager

import android.content.pm.Signature; //导入依赖的package包/类
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);
  }
 
开发者ID:stytooldex,项目名称:stynico,代码行数:27,代码来源:Update.java

示例4: install

import android.content.pm.Signature; //导入依赖的package包/类
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);
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:23,代码来源:InstalledAppTestUtils.java

示例5: isPlayServices

import android.content.pm.Signature; //导入依赖的package包/类
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;
	}
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:23,代码来源:ScreenFilterMonitorImpl.java

示例6: validateAppSignatureForPackage

import android.content.pm.Signature; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:MobileDev418,项目名称:AndroidBackendlessChat,代码行数:25,代码来源:Facebook.java

示例7: verifySignatures

import android.content.pm.Signature; //导入依赖的package包/类
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;
}
 
开发者ID:Trumeet,项目名称:MiPushFramework,代码行数:17,代码来源:MiuiPushActivateService.java

示例8: updateSignatures

import android.content.pm.Signature; //导入依赖的package包/类
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();
}
 
开发者ID:shenghaiyang,项目名称:OkSign,代码行数:23,代码来源:MainActivity.java

示例9: getPackageInfo

import android.content.pm.Signature; //导入依赖的package包/类
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;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:22,代码来源:IApkManagerImpl.java

示例10: saveSignatures

import android.content.pm.Signature; //导入依赖的package包/类
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;
            }
        }
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:25,代码来源:IApkManagerImpl.java

示例11: readSignatures

import android.content.pm.Signature; //导入依赖的package包/类
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()]);
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:24,代码来源:IApkManagerImpl.java

示例12: checkSignatures

import android.content.pm.Signature; //导入依赖的package包/类
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;
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:36,代码来源:IApkManagerImpl.java

示例13: getApplicationSignature

import android.content.pm.Signature; //导入依赖的package包/类
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;
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:27,代码来源:FacebookSdk.java

示例14: g

import android.content.pm.Signature; //导入依赖的package包/类
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;
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:22,代码来源:a.java

示例15: getRelease

import android.content.pm.Signature; //导入依赖的package包/类
/**
 * <一句话功能简述> 获取签名名
 * 
 * @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 "";
}
 
开发者ID:zhuyu1022,项目名称:amap,代码行数:32,代码来源:MIP_SystemUtils.java


注:本文中的android.content.pm.Signature类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。