I have an app which is signed and several keystore files. I'd like to update the app, so I need to find out which one of keys was used.
How can I match which keystore was used to originally sign my app against various keystores I have on my machine?
You can use Java 7's Key and Certificate Management Tool
keytool
to check the signature of a keystore or an APK without extracting any files.Signature of an APK
The output will reveal the signature owner/issuer and MD5, SHA1 and SHA256 fingerprints of the APK file
app.apk
.(Note that the
-jarfile
argument was introduced in Java 7; see the documentation for more details.)Signature of a keystore
The output will reveal the aliases (entries) in the keystore file
release.jks
, with the certificate fingerprints (MD5, SHA1 and SHA256).If the SHA1 fingerprints between the APK and the keystore match, then you can rest assured that that app is signed with the key.
To build on Paul Lammertsma's answer, this command will print the names and signatures of all APKs in the current dir (I'm using sh because later I need to pipe the output to grep):
find . -name "*.apk" -exec echo "APK: {}" \; -exec sh -c 'keytool -printcert -jarfile "{}"' \;
Sample output:
Or if you just care about SHA1:
find . -name "*.apk" -exec echo "APK: {}" \; -exec sh -c 'keytool -printcert -jarfile "{}" | grep SHA1' \;
Sample output:
Much easier way to view the signing certificate:
This will only show the DN, so if you have two certs with the same DN, you might have to compare by fingerprint.
There are many freewares to examine the certificates and key stores such as KeyStore Explorer.
Unzip the apk and open the META-INF/?.RSA file. ? shall be CERT or ANDROID or may be something else. It will display all the information associated with your apk.
First, unzip the APK and extract the file /META-INF/ANDROID_.RSA (this file may also be CERT.RSA, but there should only be one .RSA file).
Then issue this command:
You will get certificate fingerprints like this:
Then use the keytool again to print out all the aliases of your signing keystore:
You will get a list of aliases and their certificate fingerprint:
Voila! we can now determined the apk has been signed with this keystore, and with the alias 'android_key'.
Keytool is part of Java, so make sure your PATH has Java installation dir in it.