本文整理匯總了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;
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
}
}
}
示例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()]);
}
示例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;
}
}
示例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;
}
}
示例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;
}
}
示例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 "";
}