Java Code Examples for android.content.pm.Signature#toCharsString()
The following examples show how to use
android.content.pm.Signature#toCharsString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpotifyNativeAuthUtil.java From blade-player with GNU General Public License v3.0 | 6 votes |
@SuppressLint("PackageManagerGetSignatures") private boolean validateSignature(String spotifyPackageName) { try { final PackageInfo packageInfo = mContextActivity.getPackageManager().getPackageInfo(spotifyPackageName, PackageManager.GET_SIGNATURES); if (packageInfo.signatures == null) { return false; } for (Signature signature : packageInfo.signatures) { final String signatureString = signature.toCharsString(); final String sha1Signature = sha1Hash(signatureString); for (String s : SPOTIFY_SIGNATURE_HASH) { if (s.equals(sha1Signature)) { return true; } } } } catch (PackageManager.NameNotFoundException ignored) { } return false; }
Example 2
Source File: SysUtils.java From android with MIT License | 6 votes |
/** * 获取apk的签名,一长串数字 * * @param context 上下文 * @return 签名数字串 */ public static String getAppSignature(Context context) { String result = null; try { PackageManager manager = context.getPackageManager(); String pkgName = context.getPackageName(); PackageInfo packageInfo = manager.getPackageInfo(pkgName, PackageManager.GET_SIGNATURES); Signature[] signatures = packageInfo.signatures; if (null != signatures && signatures.length > 0) { Signature signature = signatures[0]; int hashCode = signature.hashCode(); result = signature.toCharsString(); LogUtils.debug(result); System.out.println(hashCode + "|" + result); } } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return result; }
Example 3
Source File: SpotifyNativeAuthUtil.java From android-auth with Apache License 2.0 | 6 votes |
@SuppressLint("PackageManagerGetSignatures") private boolean validateSignature(String spotifyPackageName) { try { final PackageInfo packageInfo = mContextActivity.getPackageManager().getPackageInfo(spotifyPackageName, PackageManager.GET_SIGNATURES); if (packageInfo.signatures == null) { return false; } for (Signature actualApkSignature : packageInfo.signatures) { final String signatureString = actualApkSignature.toCharsString(); final String sha1Signature = sha1Hash(signatureString); for (String knownSpotifyHash : SPOTIFY_SIGNATURE_HASH) { if (knownSpotifyHash.equals(sha1Signature)) { return true; } } } } catch (PackageManager.NameNotFoundException ignored) { } return false; }
Example 4
Source File: TalkProtocol.java From kakao-android-sdk-standalone with Apache License 2.0 | 6 votes |
private static boolean validateTalkSignatureAndMinVersion(final Context context, final String packageName, final int minVersion) { PackageInfo talkPackageInfo; try { talkPackageInfo = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES); } catch (PackageManager.NameNotFoundException e) { return false; } if(minVersion > 0){ if(talkPackageInfo.versionCode < minVersion) return false; } for (Signature signature : talkPackageInfo.signatures) { String signatureCharsString = signature.toCharsString(); if (signatureCharsString.equals(RELEASE_TAlk_SIGNATURE) || signatureCharsString.equals(DEBUG_TAlk_SIGNATURE)) { return true; } } return false; }
Example 5
Source File: ScalarSensorService.java From science-journal with Apache License 2.0 | 5 votes |
/** * Check that the connecting app is one we trust to stream sensor data to. * * <p>By default, this will only accept Science Journal installed from the Play Store. * * <p>Note that this method only returns valid results when called from within methods defined on * the Binder class, not methods like onBind on the service itself. */ protected boolean binderHasAllowedSignature() { int uid = Binder.getCallingUid(); PackageManager pm = getPackageManager(); String bindingName = pm.getNameForUid(uid); try { PackageInfo info = pm.getPackageInfo(bindingName, PackageManager.GET_SIGNATURES); Signature[] signatures = info.signatures; Set<String> allowedSignatures = allowedSignatures(); if (Log.isLoggable(TAG, Log.INFO)) { Log.i( TAG, "Number of signatures of binding app [" + bindingName + "]: " + signatures.length); } for (Signature signature : signatures) { String charString = signature.toCharsString(); if (Log.isLoggable(TAG, Log.INFO)) { Log.i(TAG, "Checking signature: " + charString); } if (allowedSignatures.contains(charString)) { if (Log.isLoggable(TAG, Log.INFO)) { Log.i(TAG, "Signature match!"); } return true; } } } catch (PackageManager.NameNotFoundException e) { if (Log.isLoggable(TAG, Log.ERROR)) { Log.e(TAG, "Unknown package name: " + bindingName); } } if (Log.isLoggable(TAG, Log.ERROR)) { Log.e(TAG, "Signature check failed"); } return false; }
Example 6
Source File: AndroidUtils.java From Android-Next with Apache License 2.0 | 5 votes |
public static String getSignatureInfo(Context context) { final Signature signature = getPackageSignature(context); if (signature == null) { return ""; } final StringBuilder builder = new StringBuilder(); try { final byte[] signatureBytes = signature.toByteArray(); CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); final InputStream is = new ByteArrayInputStream(signatureBytes); X509Certificate cert = (X509Certificate) certFactory.generateCertificate(is); final String chars = signature.toCharsString(); final String hex = CryptoUtils.HEX.encodeHex(signatureBytes, false); final String md5 = CryptoUtils.HASH.md5(signatureBytes); final String sha1 = CryptoUtils.HASH.sha1(signatureBytes); builder.append("SignName:").append(cert.getSigAlgName()).append("\n"); builder.append("Chars:").append(chars).append("\n"); builder.append("Hex:").append(hex).append("\n"); builder.append("MD5:").append(md5).append("\n"); builder.append("SHA1:").append(sha1).append("\n"); builder.append("SignNumber:").append(cert.getSerialNumber()).append("\n"); builder.append("SubjectDN:").append(cert.getSubjectDN().getName()).append("\n"); builder.append("IssuerDN:").append(cert.getIssuerDN().getName()).append("\n"); } catch (Exception e) { LogUtils.e(TAG, "parseSignature() ex=" + e); } final String text = builder.toString(); if (DEBUG) { LogUtils.v(TAG, text); } return text; }