import android.os.Build
import android.content.pm.PackageManager
import android.util.Base64
import androidx.annotation.RequiresApi
import java.security.MessageDigest
import android.util.Log
class MainActivity : AppCompatActivity() {
@RequiresApi(Build.VERSION_CODES.P)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
try {
val packageInfo = packageManager.getPackageInfo(
packageName, PackageManager.GET_SIGNING_CERTIFICATES
)
val signingInfo = packageInfo.signingInfo.apkContentsSigners
for (signature in signingInfo) {
val messageDigest = MessageDigest.getInstance("SHA")
messageDigest.update(signature.toByteArray())
val keyHash = String(Base64.encode(messageDigest.digest(), 0))
Log.d("KeyHash", keyHash)
}
} catch (e: Exception) {
Log.e("Exception", e.toString())
}
}
}