From 2c0e6335f49b485976de17572d0edd3cee525d90 Mon Sep 17 00:00:00 2001 From: Galeen <2math@mail.bg> Date: Fri, 7 Jun 2019 17:47:51 +0300 Subject: [PATCH] print key hash in system utils --- .../base_library/utils/SystemUtils.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/core_library/src/main/java/com/futurist_labs/android/base_library/utils/SystemUtils.java b/core_library/src/main/java/com/futurist_labs/android/base_library/utils/SystemUtils.java index 4efaa9e..3feaa80 100644 --- a/core_library/src/main/java/com/futurist_labs/android/base_library/utils/SystemUtils.java +++ b/core_library/src/main/java/com/futurist_labs/android/base_library/utils/SystemUtils.java @@ -1,11 +1,14 @@ package com.futurist_labs.android.base_library.utils; +import android.annotation.SuppressLint; import android.app.Activity; import android.app.NotificationManager; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; +import android.content.pm.PackageInfo; import android.content.pm.PackageManager; +import android.content.pm.Signature; import android.graphics.Point; import android.graphics.Rect; import android.os.Build; @@ -20,7 +23,9 @@ import android.text.Spanned; import android.text.style.StrikethroughSpan; import android.text.style.UnderlineSpan; +import android.util.Base64; import android.util.DisplayMetrics; +import android.util.Log; import android.view.Display; import android.view.View; import android.view.Window; @@ -36,6 +41,8 @@ import com.futurist_labs.android.base_library.utils.photo.HttpImageGetter; import com.futurist_labs.android.base_library.views.font_views.FontHelper; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; import java.util.UUID; //import com.google.android.gms.maps.model.BitmapDescriptor; @@ -381,4 +388,26 @@ public static void pasteInClipboard(Context context, String text, String label) ClipData clip = ClipData.newPlainText(label, text); clipboard.setPrimaryClip(clip); } + + /** + * Use this helper method to print your keyHash in logs, don't use it in production + * + * @param activity context + */ + public static void printKeyHash(Activity activity) { + try { + @SuppressLint("PackageManagerGetSignatures") + PackageInfo info = activity.getPackageManager().getPackageInfo( + activity.getPackageName(), PackageManager.GET_SIGNATURES); + for (Signature signature : info.signatures) { + MessageDigest md = MessageDigest.getInstance("SHA"); + md.update(signature.toByteArray()); + Log.e("MY KEY HASH:", Base64.encodeToString(md.digest(), Base64.DEFAULT)); + } + } catch (PackageManager.NameNotFoundException e) { + LogUtils.d(e.getMessage()); + } catch (NoSuchAlgorithmException e) { + LogUtils.d(e.getMessage()); + } + } }