Skip to content

Instantly share code, notes, and snippets.

@dev-donghwan
Last active August 12, 2021 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dev-donghwan/3e124e6cae8799cf04b4146d46a3b71d to your computer and use it in GitHub Desktop.
Save dev-donghwan/3e124e6cae8799cf04b4146d46a3b71d to your computer and use it in GitHub Desktop.
Android GetHashKey
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