Created
September 3, 2020 12:09
-
-
Save Gongcu/253fdb56a1fd168b6a79a856a32a52c7 to your computer and use it in GitHub Desktop.
Android Get Hash Key Method
This file contains hidden or 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 getHashKey(){ | |
| val info: PackageInfo | |
| try { | |
| info = packageManager.getPackageInfo("com.example.a2ndaccidentprevention", PackageManager.GET_SIGNATURES) | |
| for (signature in info.signatures) { | |
| var md: MessageDigest | |
| md = MessageDigest.getInstance("SHA") | |
| md.update(signature.toByteArray()) | |
| val something: String = String(Base64.encode(md.digest(), 0)) | |
| //String something = new String(Base64.encodeBytes(md.digest())); | |
| Log.e("hash key", something) | |
| } | |
| } 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()) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment