Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
generateHashkey Linked In
fun generateHashkey() {
try {
if (Build.VERSION.SDK_INT >= 28) {
@SuppressLint("WrongConstant") val packageInfo = getPackageManager().getPackageInfo(
getPAckageName(), PackageManager.GET_SIGNING_CERTIFICATES
)
val signatures = packageInfo.signingInfo.getApkContentsSigners()
val md = MessageDigest.getInstance("SHA")
for (signature in signatures) {
md.update(signature.toByteArray())
val signatureBase64 = String(Base64.encode(md.digest(), Base64.DEFAULT))
Timber.d("Signature Base64 : " + signatureBase64)
}
}
} catch (e: PackageManager.NameNotFoundException) {
e.printStackTrace()
} catch (e: NoSuchAlgorithmException) {
e.printStackTrace()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment