Android app Key Hash doesn't match any stored key hashes
Asked Answered
P

14

33

I have an application on production on Play Store which uses a login with the Facebook SDK. When I debug the application from Eclipse there is no problem, but when its on production it gives me the following error after Facebook asks me for the permissions. I have added on my app page on developers.facebook.com the key hash generated with keytool using this command:

keytool -exportcert -alias diego -keystore "C:\Users\Diego\Desktop\CeluChat.KeyStore" | "C:\openssl\bin\openssl.exe" sha1 -binary | "C:\openssl\bin\openssl.exe" base64

CeluChat.KeyStore is the keystore I used when I exported the signed application, and when keytool promts me for the password, I entered the same when exported.

But the error that gives me on production (downloaded from Play Store) is:

10-20 22:21:10.752: W/fb4a(:):BlueServiceQueue(5872): com.facebook.http.protocol.ApiException: Key hash VQ3XhZb5_tBH9oGe2WW32DDdNS0 does not match any stored key hashes.

The Key Hash that is on the exception is different from the key hash generated with keytool. Anyway I added the Key Hash on Facebook, but it is still not working.

Parliamentary answered 21/10, 2013 at 1:39 Comment(4)
There are today a global problem in Facebook, check it laterHaiduk
When you submit an apk for the play store, usually that's using a different keystore than when you're in development, which would give you a different key hash. You need to put both key hashes into your settings. Are you sure that the value given in the error doesn't work either? Can you post a screen shot of your app settings?Correct
The key hash that I was generating with keytool was with the relase key, not with the debug, so the problem was not that. Thanks anywayParliamentary
If you are copying the key hash from log and using it, note that in the log it does not print with a = in the end, you must suffix a = to what is printed in the log and then use it in the Facebook key hash.Craver
S
29

Facebook some how replaces +,- and / with _

So just try replacing _ with +, - and / and add that hash-key.

Hopefully it should work.

Superfecundation answered 21/10, 2013 at 16:1 Comment(9)
To find the EXACT value that you need, run this command (it will require your keystore password): keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | openssl sha1 -binary | openssl base64Hepzi
the hash key should contain '='?Cloak
I have none of these symbols in my key, so nothing to replace there. = is at the end, it´s exactly the same key as the log says, but nothing is workingVaishnava
I need to replace "_" instead of "/" on my hasy key. But im little bit confusing where should i replace. Im using following key on my facebook app. gtKHgB36QgyFMUrCFDtAFdKrc/8=Balinese
This is a poor method as it's just hit and trial, it may vary. Adding Trailing '=' also doesn't seem to work now.Urbina
same as @Youngjae, I just added '=' at the end. This is insane.Gaslit
I had to get over to developers.facebook.com, select the app and then "settings" on the left. Scroll down to Android => add the key here, for some reason it would only show the release key hash there, adding the debug key hash there fixed it for me.Sicilia
Just for heads up, when using Win PowerShell then the hash will have a different value and no '=' in the end which will give you the trailing '=' error. I did the same commands with original cmd and it worked. Don't know why PowerShell messes it up.Oboe
I am also getting Hashkey error for Facebook login.. but it is working fine in few apps and not working in few apps.. i am totally confuse what to do.. I have change the hash key many times then also I am facing this problem. My App is publish on playstore that time I am getting this error., When I directly install from androidStudio it is working fine..please Help..Schmuck
M
29

I used this to show the key when I ran my app. In my case, I was getting the incorrect key hash from the keytool command. Notice that if you enter the wrong password(purposely), instead of receiving an error an incorrect key is generated. Use this to get the correct hash and see if it matches the one the in the error log

try {
        PackageInfo info =     getPackageManager().getPackageInfo("com.package.mypackage",     PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            String sign=Base64.encodeToString(md.digest(), Base64.DEFAULT);
            Log.e("MY KEY HASH:", sign);
            Toast.makeText(getApplicationContext(),sign,     Toast.LENGTH_LONG).show();
        }
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}

Also, if for some reason the above method does not work. Try using this APK to generate the correct key hash. Remember that you have to sign it with whatever certificate you are trying to retrieve(debug or release). Install it on your testing device, and run it.

http://www.easyfacebookandroidsdk.com/download/keyhash.zip

Migraine answered 21/10, 2013 at 2:38 Comment(4)
I used that code and discovered that the key hash was the same that facebook gives on the exception, but replacing "_" with "/" and adding a "=" on the end. ThanksParliamentary
It didn't replace anything for me but missed the "=" at the end too.Glyptodont
@DiegoSuárez how to replace "_" with "/" I have just changed it but it is not getting saved there as Keyhash. Please let me know the way for that.Defense
This work for me. The command with keytool and openssl in the official doc return the difference hash. :((Tuning
S
29

Facebook some how replaces +,- and / with _

So just try replacing _ with +, - and / and add that hash-key.

Hopefully it should work.

Superfecundation answered 21/10, 2013 at 16:1 Comment(9)
To find the EXACT value that you need, run this command (it will require your keystore password): keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | openssl sha1 -binary | openssl base64Hepzi
the hash key should contain '='?Cloak
I have none of these symbols in my key, so nothing to replace there. = is at the end, it´s exactly the same key as the log says, but nothing is workingVaishnava
I need to replace "_" instead of "/" on my hasy key. But im little bit confusing where should i replace. Im using following key on my facebook app. gtKHgB36QgyFMUrCFDtAFdKrc/8=Balinese
This is a poor method as it's just hit and trial, it may vary. Adding Trailing '=' also doesn't seem to work now.Urbina
same as @Youngjae, I just added '=' at the end. This is insane.Gaslit
I had to get over to developers.facebook.com, select the app and then "settings" on the left. Scroll down to Android => add the key here, for some reason it would only show the release key hash there, adding the debug key hash there fixed it for me.Sicilia
Just for heads up, when using Win PowerShell then the hash will have a different value and no '=' in the end which will give you the trailing '=' error. I did the same commands with original cmd and it worked. Don't know why PowerShell messes it up.Oboe
I am also getting Hashkey error for Facebook login.. but it is working fine in few apps and not working in few apps.. i am totally confuse what to do.. I have change the hash key many times then also I am facing this problem. My App is publish on playstore that time I am getting this error., When I directly install from androidStudio it is working fine..please Help..Schmuck
D
10

I just discovered a bug with the Sample App key entry page: If you paste a hash key from the app without hitting Enter, and then click the "Save Changes" button, the newly entered code will disappear but the page will show a "Saved!" response message. This isn't true: it didn't save. You must hit the Enter key after pasting the hash key and then hit "Save Changes".

I saved a key including the trailing = character. That worked.

Danu answered 12/2, 2014 at 2:51 Comment(2)
True. I faced this problem. It creates a box to separate it from other keys. They should implement some script to convert automatically. No one will press enter on a single line box. Thanks :)Harhay
I faced a funny situation, my app faces this issue after being live on Google Play, and when facebook dialog show error about key hash, it can't be copied to clipboard, so I have to TYPE it MANUALLY. And my eyes got tricked by I (i uppercase) and l (L lowercase). It cost me 3 hours to find outSugihara
U
8

Please follow below method to generate hash key this is suggested by @lucianbase at this page https://github.com/AntonioCuevaUrraco/nativescript-facebook-login/issues/14

Generate SHA1 key of your app either using android studio or cmd tool. copy it like this CD:A1:EA:A3:5C:5C:68:FB:FA:0A:6B:E5:5A:72:64:DD:26:8D:44:84 and open http://tomeko.net/online_tools/hex_to_base64.php to convert your SHA1 value to base64. This is what Facebook requires get the generated hash " ********************= " and copy the key hash to the facebook app.

Uniform answered 9/6, 2018 at 13:29 Comment(2)
This is what did it for me. Thank you. None of the other ones worked at all.Dyl
This worked for me using the SHA1 of the App signing certificate stored in Google, thanks! For those having issues on the Play Store release but not locally: you basically have to generate the key hash using the key that you used to sign the app on production – which is normally handled by Google.Winburn
T
7

Simple put the returned error message hash key:

10-20 22:21:10.752: W/fb4a(:):BlueServiceQueue(5872): com.facebook.http.protocol.ApiException: Key hash VQ3XhZb5_tBH9oGe2WW32DDdNS0 does not match any stored key hashes.

VQ3XhZb5_tBH9oGe2WW32DDdNS0

On Facebook developers key hashes of your app.

Hope this help.

Twinflower answered 15/3, 2014 at 2:9 Comment(3)
The problem was solved. Have a look at the answers. And refering to your answer, read again the last paragraph of the question. Thanks anywayParliamentary
Note that you may need to suffix a '=' to the key hash you see in the logs, before using it in your app key hash definition.Craver
Is that different hash key for different mobiles?Sidelight
S
7

Well, If u r using Windows use this command in cmd .

Move to C:\Program Files\Java\jdk1.8.0_25\bin

keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | "C:\openssl\bin\openssl.exe" sha1 -binary | "C:\openssl\bin\openssl.exe" base64

When generating the hash key you need to use openssl-0.9.8e_X64.zip on windows, you cannot use openssl-0.9.8k_X64.zip

This is the solution.

Senseless answered 12/5, 2015 at 9:41 Comment(1)
Worked.. Help me a lotDatum
U
5

It is a nice question. And there are 2 ways to go about it. What usually happens with us is while integrating Facebook SDK for android, we go on following instructions from the Developer site of facebook.

But once the app is out in the play-store, we tend to forget a procedure that still is pending. And we end upon same error :

05-13 14:45:43.882: W/fb4a(:<default>):BlueServiceQueue(25454): Exception during service
05-13 14:45:43.882: W/fb4a(:<default>):BlueServiceQueue(25454): com.facebook.http.protocol.ApiException: Key hash XXXXXXXXXXXXXX does not match any stored key hashes.

Jus got a checklist for this:

1) Using debug Key, while developing the App

The Facebook developer site is quite helpful with this. Just copy paste the code they have in the Getting started page into your command prompt. viz:

keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64

The password to it is android and you will get the debug key following it.

enter image description here

2) Generating Debug Key, after signing the application

Once the application is ready to be uploaded to the Google Play store, we need to sign it using a key, value of which is generated from the key store. Which is explained well by Satheesh in his answer. using :

keytool -exportcert -alias <Alias Name here> -keystore <Path to keystore> | openssl sha1 -binary | openssl base64

Which gives you a different key, than the debug key.

enter image description here

Urbina answered 13/5, 2014 at 10:12 Comment(0)
S
3

After trying all the above i tried this.. and worked!!!

  1. Copy the key hash was the same that Facebook gives on the exception,
  2. Replace "_" with "/" and adding a "=" on the end,
  3. Add it to Facebook
  4. Also check the package name and activity name once again. This worked for me!!.
Syntactics answered 19/4, 2014 at 10:12 Comment(0)
Y
1

well the actually best and easy way is like this. if you see that problem on your phone screen. You should see that problem with android studio LOGCAT. it will like this

01-26 14:58:22.885 14851-19534/? W/fb4a.BlueServiceQueue: Exception during service
                                                          X.1xO: [code] 404 [message]: Key hash 961x8mIbWmA7TRRpbk...= does not match any stored key hashes. (404) [extra]: null
                                                              at X.0fG.D(:240135)
                                                              at X.0k8.F(:255078)
                                                              at X.3gX.EUB(:738232)
                                                              at X.0fo.handleResponse(:242693)
                                                              at X.0k5.run(:254998)
                                                              at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
                                                              at X.0NH.run(:187661)
                                                              at X.0JQ.run(:49671)
                                                              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
                                                              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
                                                              at X.0NM.run(:187873)
                                                              at java.lang.Thread.run(Thread.java:761)

copy this hash key from logcat which is I had made it private (...) and paste it to your facebook developer page. It will solve your problem immediately. Also be ensure that your released APK's hash key different from the original hash key which is download from google play.

Ypres answered 26/1, 2018 at 12:35 Comment(1)
Best solution. Thanks.Eristic
A
0

Just Replace The Error Key Hash Within Your https://developers.facebook.com/app application...!

100 Percentage It Will Work For Sure.

-Sunil

Aut answered 1/2, 2017 at 10:8 Comment(0)
B
0

For the released version, generate hash key using this line :

keytool -exportcert -alias foodtimeph -keystore /Users/eliedanhash/Downloads/ph/foodtimeph.keystore.jks | openssl sha1 -binary | openssl base64
Brewer answered 21/10, 2020 at 17:14 Comment(0)
M
0

If you have you app on the google app store just go to => => and copy your SHA-1 key. Then go to this website and copy in your SHA-1 key in the top textbar link

The copy the key hash (output base64) to your facebook key hash field. everything should work now. :D

Mic answered 2/11, 2020 at 22:33 Comment(0)
M
0
import android.content.pm.PackageManager
import android.util.Base64
import android.util.Log
import java.security.MessageDigest
import java.security.NoSuchAlgorithmException       


  try {
        val info = packageManager.getPackageInfo("your package 
    name", 
           PackageManager.GET_SIGNATURES)
        for (signature in info.signatures) {
            val md = MessageDigest.getInstance("SHA")
            md.update(signature.toByteArray())
            Log.e("KeyHash:", Base64.encodeToString(md.digest(), 
                       Base64.DEFAULT))
        }
    } catch (e: PackageManager.NameNotFoundException) {
        Log.e("","")
    } catch (e: NoSuchAlgorithmException) {
        Log.e("","")

    }

i searched lot doesnt work, finally i found this, kotlin version Facebook login issue

Monolith answered 5/10, 2021 at 7:22 Comment(0)
I
-1

Enable Single Sign On Enable single sign on for your app by setting Single Sign On to Yes below. please check point no. 9 on https://developers.facebook.com/docs/facebook-login/android

Ineducation answered 16/12, 2016 at 6:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.