Created
July 16, 2017 12:47
-
-
Save tinmegali/c2d0e9e9f02435d116aa27016901715b to your computer and use it in GitHub Desktop.
Getting Hash on Android programatically using Kotlin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
val info = packageManager.getPackageInfo( | |
"com.mypackage.name", // TODO Change the package name | |
PackageManager.GET_SIGNATURES) | |
for (signature in info.signatures) { | |
val md = MessageDigest.getInstance("SHA") | |
md.update(signature.toByteArray()) | |
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT)) | |
} | |
} catch (e: PackageManager.NameNotFoundException) { | |
} catch (e: NoSuchAlgorithmException) { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment