Created
November 5, 2014 09:07
-
-
Save kanytu/6dfc557a53870e06e1d0 to your computer and use it in GitHub Desktop.
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
private static final int VALID = 0; | |
private static final int INVALID = 1; | |
public static int checkAppSignature(Context context) { | |
try { | |
PackageInfo packageInfo = context.getPackageManager() | |
.getPackageInfo(context.getPackageName(), | |
PackageManager.GET\_SIGNATURES); | |
for (Signature signature : packageInfo.signatures) { | |
byte[] signatureBytes = signature.toByteArray(); | |
MessageDigest md = MessageDigest.getInstance("SHA"); | |
md.update(signature.toByteArray()); | |
final String currentSignature = Base64.encodeToString(md.digest(), Base64.DEFAULT); | |
Log.d("REMOVE\_ME", "Include this string as a value for SIGNATURE:" + currentSignature); | |
//compare signatures | |
if (SIGNATURE.equals(currentSignature)){ | |
return VALID; | |
}; | |
} | |
} catch (Exception e) { | |
//assumes an issue in checking signature., but we let the caller decide on what to do. | |
} | |
return INVALID; | |
} | |
Get expert java help |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
Please help me to check my apk signature.
I use android studio.
.
from tutorial on : https://www.airpair.com/android/posts/adding-tampering-detection-to-your-android-app
10-10 17:37:11.483: D/REMOVE_ME:(111):
I really not know how to find it, I already check on logcat too.
.
thank you