Last active
March 30, 2020 19:40
-
-
Save gungoren/e364a92047f15343407d33ce11d4f94e to your computer and use it in GitHub Desktop.
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
private void getApkSignatureHash() { | |
PackageManager packageManager = context.getPackageManager(); | |
String packageName = context.getPackageName(); | |
//Solution 1 | |
try { | |
PackageInfo packageInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNING_CERTIFICATES); | |
//Deprecated packageInfo.signatures; | |
Signature[] signatures = packageInfo.signatures; | |
Signature signature = signatures[0]; | |
String sign = signature.toCharsString(); | |
String hash = md5(sign); | |
} catch (PackageManager.NameNotFoundException e) { | |
e.printStackTrace(); | |
} | |
/* | |
Solution 2 | |
try { | |
PackageInfo packageInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNING_CERTIFICATES); | |
SigningInfo signingInfo = packageInfo.signingInfo; | |
Signature[] signatures = signingInfo.getApkContentsSigners(); | |
Signature signature = signatures[0]; | |
String sign = signature.toCharsString(); | |
String hash = md5(sign); | |
} catch (PackageManager.NameNotFoundException e) { | |
e.printStackTrace(); | |
} | |
*/ | |
} |
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 getApkSignatureHash() { | |
val packageManager = context.packageManager | |
val packageName = context.packageName | |
//Solution 1 | |
try { | |
val packageInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNING_CERTIFICATES) | |
//Deprecated packageInfo.signatures; | |
val signatures = packageInfo.signatures | |
val signature = signatures[0] | |
val sign = signature.toCharsString() | |
val hash: String = md5(sign) | |
} catch (e: PackageManager.NameNotFoundException) { | |
e.printStackTrace() | |
} | |
/* | |
//Solution 2 | |
try { | |
val packageInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNING_CERTIFICATES) | |
val signingInfo = packageInfo.signingInfo | |
val signatures = signingInfo.getApkContentsSigners() | |
val signature = signatures[0] | |
val sign = signature.toCharsString() | |
val hash = md5(sign) | |
} catch (e: PackageManager.NameNotFoundException) { | |
e.printStackTrace(); | |
} | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
md5 function from @dlimpid : https://gist.github.com/dlimpid/68761108b49b7c1ddb84250dfac78495