Created
July 25, 2014 02:51
-
-
Save vaibhavpandeyvpz/91b6ea016ce063d96e25 to your computer and use it in GitHub Desktop.
Generate Hash of Application Signature in Android
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
import java.security.MessageDigest; | |
import android.content.Context; | |
import android.content.pm.PackageInfo; | |
import android.content.pm.PackageManager; | |
import android.content.pm.Signature; | |
import android.util.Base64; | |
class Signature { | |
public static String hash(Context context) { | |
return hash(context, context.getPackageName()); | |
} | |
public static String hash(Context context, String packag) { | |
try { | |
PackageInfo info = context.getPackageManager().getPackageInfo(packag, PackageManager.GET_SIGNATURES); | |
Signature signature = info.signatures[0]; | |
MessageDigest digest = MessageDigest.getInstance("SHA"); | |
digest.update(signature.toByteArray()); | |
return Base64.encodeToString(digest.digest(), Base64.DEFAULT); | |
} catch (Exception exception) { | |
exception.printStackTrace(); | |
return null; | |
} | |
} | |
} |
Antibio24
commented
Jun 25, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment