Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find the key hash for a signed app

I have signed my app and exported it to a folder on my desktop called app in this folder is my app itself and the keystore. How do i find the key hash that i can copy into the facebook developers page. i have openssl installed but cant seem to generate the key hash ive tried many other threads on stack and none have seemed to help, thanks

James

like image 289
James Avatar asked Apr 27 '11 12:04

James


People also ask

Where can I find key hashes?

Click "Show Advanced Settings", and in the "Device Settings" tab, under "Android", fill the "App Package Name" with your application's package name, and the "Key Hashes" field with the SHA256 value you copied.

What is key hash in Android?

You will have to enter a password. The password is: android. A code will come up and that code is your key hash.

How do I check which signing keys were used?

Signature of a keystore Note that if you are using Play App Signing, your upload key may differ from the key used by Google Play to sign your app. In this case, you can find the app signature from the Google Play Console on the Release > Setup > App Integrity page.


2 Answers

  1. You should know where is your keystore file. For me is C:\Users\Selvin\Desktop\selvin.kp
  2. You should know your alias in keystore. For me is selvin
  3. You should know path to keytool. C:\Program Files\Java\jdk1.6.0_22\bin\keytool.exe
  4. You should know path to openssl. C:\OpenSSL-Win32\bin\openssl.exe
  5. You should know password to keystore. For me is ***** hehe

Then, you should call:

C:\Program Files\Java\jdk1.6.0_22\bin\keytool.exe" -exportcert -alias selvin -keystore c:\users\selvin\desktop\selvin.kp | C:\OpenSSL-Win32\bin\openssl sha1 -binary | C:\OpenSSL-Win32\bin\openssl base64

Replace my path and alias with proper ones.

Then you should see:

Enter keystore password:

Enter your password and you should get something like this: NfhDlIH7XWJzUZRjL+pZySrMX1Q=

EDITED: NfgDlIG7XWJzUZRUL+bZySrMX1Q= <- is a bad hash. Or you got so lucky that your key made the same collision as

error:keytool error: java.lang.Exception: Alias does not exist

If hash not working:

First, call

C:\Program Files\Java\jdk1.6.0_22\bin\keytool.exe" -exportcert -alias selvin -keystore c:\users\selvin\desktop\selvin.kp

Type password and read the error

If you don't remember your alias keytool error: java.lang.Exception: Alias <selvinn> does not exist I used selvinn to show error.

For a list of all your entries/aliases:

C:\Program Files\Java\jdk1.6.0_22\bin\keytool.exe -list -keystore c:\users\selvin\desktop\selvin.kp

second edit

enter image description here

like image 124
Selvin Avatar answered Oct 09 '22 10:10

Selvin


For those still struggling I have found that these steps when followed correctly will certainly work but they can be quite challenging to get right first time, and actually I have found that sometimes the base64 conversion of the fingerprint when dealing with some alias' do not work (the hash gets truncated for some reason). I've written various batch files that pull most of these instructions already mentioned together so I don't rule out a problem there.

However, essentially most people fall down at the openssl stage (either can't find it, don't know how to use it, or Windows piping doesn't correctly chain the output from the SHA1 export to the base64 conversion input).

To get around this you can use an alternative method which is probably easier to follow and understand. Essentially what the facebook API wants is the base64 representation (encoding) of the SHA1 hash used to fingerprint your APK. To do this you can just list the keystore:

"C:\Program Files\Java\JRE6\Bin\keytool.exe" -list -v -keystore "Path-to-your-keystore" -storepass "KeystorePassword" > somefile.txt

Obviously you need to change the path to the keytool executable according to your own setup, and replace "Path-to-your-keystore" and "KeystorePassword" with your keystore path and password! The result should be the creation of a file "sometext.txt" in the current folder which you can then open in any text editor. The text file will list all of the keystore alias' and their respective MD5 and SHA1 hashes as hex strings.

Now just find the alias used to sign your APK, copy the SHA1 hash, and use any online hex to base64 converter to convert it to the base64 encoding format that facebook requires. You can find an online converter by googling "online hex to base64 converter". I've been using this one as you can just copy and paste the string right from the text file in to the box provided and it will just remove the colons that separate each hex byte.

One final point (somewhat obvious but..) only copy and paste the hex string and NOT the SHA1: prefix!

Hope this helps someone; it certainly works for me!

like image 22
sriggall Avatar answered Oct 09 '22 10:10

sriggall