Skip to content

Instantly share code, notes, and snippets.

@ecentinela
Created December 5, 2012 20:11
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save ecentinela/4219061 to your computer and use it in GitHub Desktop.
Save ecentinela/4219061 to your computer and use it in GitHub Desktop.
Get Android application signature
PackageInfo info;
try {
info = getPackageManager().getPackageInfo("ecentinela.mercadotes", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md;
md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
String something = new String(Base64.encode(md.digest(), 0));
//String something = new String(Base64.encodeBytes(md.digest()));
Log.e("hash key", something);
}
}
catch (NameNotFoundException e1) {
Log.e("name not found", e1.toString());
}
catch (NoSuchAlgorithmException e) {
Log.e("no such an algorithm", e.toString());
}
catch (Exception e){
Log.e("exception", e.toString());
}
@cybogado
Copy link

This is not really the signature, but the certificate that has signed the apk.

@majidsa70
Copy link

this solution is deprecated!
this solution is very simple hacked!
how to use PackageInfo.GET_SIGNING_CERTIFICATES in API 28 !?

@gallinaettore
Copy link

You can follow this example: https://stackoverflow.com/questions/52041805/how-to-use-packageinfo-get-signing-certificates-in-api-28

If it helps, please vote UP my post.

@mahdi-malv
Copy link

You can follow this example: https://stackoverflow.com/questions/52041805/how-to-use-packageinfo-get-signing-certificates-in-api-28

If it helps, please vote UP my post.

I added and update to that question.

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