Skip to content

Instantly share code, notes, and snippets.

@rahulkhatri19
Created February 18, 2020 04:49
Show Gist options
  • Save rahulkhatri19/ccff57f7f00d34f829e0bcc6a323f14d to your computer and use it in GitHub Desktop.
Save rahulkhatri19/ccff57f7f00d34f829e0bcc6a323f14d to your computer and use it in GitHub Desktop.
// Call printHashKey(this) method in onCreate method.
fun printHashKey(context: Context) {
try {
val info =
context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES)
for (signature in info.signatures) {
val md = MessageDigest.getInstance("SHA")
md.update(signature.toByteArray())
val hashKey = String(Base64.encode(md.digest(), 0))
Log.e("Key hash", "printHashKey() Hash Key: $hashKey")
}
} catch (e: NoSuchAlgorithmException) {
Log.e("Key hash", "printHashKey()", e)
} catch (e: Exception) {
Log.e("Key hash", "printHashKey()", e)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment