List of usage examples for android.content.pm Signature toByteArray
public byte[] toByteArray()
From source file:Main.java
/** * A double check about app signature that was passed by MainActivity as facetID. * @param facetId a string value composed by app hash. I.e. android:apk-key-hash:Lir5oIjf552K/XN4bTul0VS3GfM * @param context Application Context//from w ww . j a v a2 s.c om * @return true if the signature executed on runtime matches if signature sent by MainActivity */ private static boolean checkAppSignature(String facetId, Context context) { try { PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES); for (Signature sign : packageInfo.signatures) { byte[] sB = sign.toByteArray(); MessageDigest messageDigest = MessageDigest.getInstance("SHA1"); messageDigest.update(sign.toByteArray()); String currentSignature = Base64.encodeToString(messageDigest.digest(), Base64.DEFAULT); if (currentSignature.toLowerCase().contains(facetId.split(":")[2].toLowerCase())) { return true; } } } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return false; }
From source file:Main.java
public static String getSignatureString(Signature sig, String type) { byte[] hexBytes = sig.toByteArray(); String fingerprint = "error!"; try {/* w w w. ja v a 2 s . c o m*/ MessageDigest digest = MessageDigest.getInstance(type); if (digest != null) { byte[] digestBytes = digest.digest(hexBytes); StringBuilder sb = new StringBuilder(); for (byte digestByte : digestBytes) { sb.append((Integer.toHexString((digestByte & 0xFF) | 0x100)).substring(1, 3)); } fingerprint = sb.toString(); } } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return fingerprint; }
From source file:Main.java
public static String getSignature(Context context) { PackageManager pm = context.getPackageManager(); PackageInfo pi = null;//from w w w . j a va2 s. c o m StringBuilder builder = new StringBuilder(); try { pi = pm.getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES); Signature[] signatures = pi.signatures; for (Signature signature : signatures) { builder.append(getMessageDigest(signature.toByteArray())); } return builder.toString(); } catch (Exception e1) { e1.printStackTrace(); return ""; } }
From source file:Main.java
public static void printOutMyHashKey(Context context, String packageName) { try {// www. j a v a 2s. c om PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 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 e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } }
From source file:Main.java
public static String getHashKey(Context context) { // Add code to print out the key hash try {//w w w .j a v a 2s . co m PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES); for (Signature signature : info.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); return Base64.encodeToString(md.digest(), Base64.DEFAULT); } } catch (NameNotFoundException e) { } catch (NoSuchAlgorithmException e) { } return null; }
From source file:Main.java
/** * Print hash key/* w w w. j a va 2 s .c o m*/ */ public static void printHashKey(Context context) { try { PackageInfo info = context.getPackageManager().getPackageInfo(TAG, PackageManager.GET_SIGNATURES); for (Signature signature : info.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); String keyHash = Base64.encodeToString(md.digest(), Base64.DEFAULT); Log.d(TAG, "keyHash: " + keyHash); } } catch (NameNotFoundException e) { } catch (NoSuchAlgorithmException e) { } }
From source file:Main.java
public static String keyHash(Context context) { String key = ""; try {// w w w. j av a 2 s .co m PackageInfo info = context.getPackageManager().getPackageInfo("org.tathva.triloaded.anubhava", PackageManager.GET_SIGNATURES); for (Signature signature : info.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); key = Base64.encodeToString(md.digest(), Base64.DEFAULT); Log.d("anas", key); } } catch (NameNotFoundException e) { } catch (NoSuchAlgorithmException e) { } return key; }
From source file:Main.java
/** * @param context//from w w w .j av a 2 s .c o m * @return KeyHash * follow facebook developers link to get release key hash * https://developers.facebook.com/docs/android/getting-started#release-key-hash */ public static String getKeyHash(Context context) { PackageInfo packageInfo; String key = null; try { packageInfo = context.getPackageManager().getPackageInfo( context.getApplicationContext().getPackageName(), PackageManager.GET_SIGNATURES); for (Signature signature : packageInfo.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT)); } } catch (PackageManager.NameNotFoundException e1) { } catch (NoSuchAlgorithmException e) { } catch (Exception e) { } return key; }
From source file:Main.java
public static void printHashKey(Context context) { try {// ww w .j ava 2 s . c o m PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES); for (android.content.pm.Signature signature : info.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); Log.e("HASH KEY:", Base64.encodeToString(md.digest(), Base64.DEFAULT)); } } catch (PackageManager.NameNotFoundException e) { } catch (NoSuchAlgorithmException e) { } }
From source file:Main.java
public static void printKeyHash(Activity pActivity) { // Add code to print out the key hash try {//from w w w . j a va 2s . c o m PackageInfo info = pActivity.getPackageManager().getPackageInfo(pActivity.getPackageName(), 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 e) { Log.d("KeyHash:", e.toString()); } catch (NoSuchAlgorithmException e) { Log.d("KeyHash:", e.toString()); } }