oauth - Android: How to get SHA1/MD5 fingerprint programmatically? - Stack Overflow

PHOTO EMBED

Thu Dec 14 2023 15:22:15 GMT+0000 (Coordinated Universal Time)

Saved by @iamjasonli

fun getSig(context: Context, key: String) {
            try {
                val info = context.packageManager.getPackageInfo(
                    BuildConfig.APPLICATION_ID,
                    PackageManager.GET_SIGNATURES
                )
                for (signature in info.signatures) {
                    val md = MessageDigest.getInstance(key)
                    md.update(signature.toByteArray())
                    val digest = md.digest()
                    val toRet = StringBuilder()
                    for (i in digest.indices) {
                        if (i != 0) toRet.append(":")
                        val b = digest[i].toInt() and 0xff
                        val hex = Integer.toHexString(b)
                        if (hex.length == 1) toRet.append("0")
                        toRet.append(hex)
                    }
                    val s = toRet.toString()
                    Log.e("sig", s)
                    
                }
            } catch (e1: PackageManager.NameNotFoundException) {
                Log.e("name not found", e1.toString())
            } catch (e: NoSuchAlgorithmException) {
                Log.e("no such an algorithm", e.toString())
            } catch (e: Exception) {
                Log.e("exception", e.toString())
            }
}
content_copyCOPY

https://stackoverflow.com/questions/46410512/android-how-to-get-sha1-md5-fingerprint-programmatically