Skip to content

Instantly share code, notes, and snippets.

@vaibhavpandeyvpz
Created July 25, 2014 02:51
Show Gist options
  • Save vaibhavpandeyvpz/91b6ea016ce063d96e25 to your computer and use it in GitHub Desktop.
Save vaibhavpandeyvpz/91b6ea016ce063d96e25 to your computer and use it in GitHub Desktop.
Generate Hash of Application Signature in Android
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
Copy link

Uploading 20240608_121903.jpg…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment