-
-
Save dev-donghwan/3e124e6cae8799cf04b4146d46a3b71d to your computer and use it in GitHub Desktop.
Android GetHashKey
This file contains 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
private fun getHashKey() { | |
try { | |
if (Build.VERSION.SDK_INT > 28) { | |
for (a in packageManager.getPackageInfo( | |
packageName, | |
PackageManager.GET_SIGNING_CERTIFICATES | |
).signingInfo.apkContentsSigners) { | |
toLog(a.toByteArray()) | |
} | |
} else { | |
for (a in packageManager.getPackageInfo( | |
packageName, | |
PackageManager.GET_SIGNATURES | |
).signatures) { | |
toLog(a.toByteArray()) | |
} | |
} | |
} catch (e: Exception) { | |
e.printStackTrace(); | |
} | |
} | |
private fun toLog(byteArray: ByteArray) { | |
try { | |
val md = MessageDigest.getInstance("SHA") | |
md.update(byteArray) | |
Log.d("KeyHash", Base64.encodeToString(md.digest(), Base64.DEFAULT)) | |
} catch (e: Exception) { | |
e.printStackTrace() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment