Created
October 22, 2018 12:58
-
-
Save alouanemed/4bc204e383c19c535c514a1b367384ce to your computer and use it in GitHub Desktop.
generateHashkey Linked In
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
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