tinmegali
7/16/2017 - 12:47 PM

Getting Hash on Android programatically using Kotlin

Getting Hash on Android programatically using Kotlin

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) {

        }