Facebook 密钥哈希与任何存储的密钥哈希都不匹配

我在 Facebook 的哈希键上遇到了点麻烦。 我在 Eclipse 中生成了它. . 证明:

然后我去 https://developers.facebook.com/注册了一个新的应用程序。

最后,我将我的哈希键设置为 Facebook 开发者的设置:

但是不管我做什么,我总是得到相同的错误日志: “密钥哈希 B5dWUEYfZJL/... ... ... ... jyA = 不匹配任何存储的密钥哈希”

有人知道我做错了什么或者我该怎么解决这个问题吗? 如果我在自己的应用程序中使用 HelloFacebookSample 中的 ID 和名称,那么一切都会正常工作。 因此,它必须与密钥哈希,id 或名称,我已经设置的地方最有可能. 。

谢谢, 延特

168809 次浏览

After hours of trying I've finally found a solution.

  1. Delete any app on the website of Facebook (developers.facebook.com)
  2. Delete the file debug.keystore under C:\Users\yourUserName\.android
  3. Generate a new key (by running your app again)
  4. Create a new app on developers.facebook.com and add the new hash key
  5. Re-run your app
  6. Succes!

Adding SHA1 keys from Eclipse/keytool helped me only when creating the app on FB, then after rebuilding I would always get the OP error.

What solved my issue was adding the key in the error message to the Facebook dashboard settings.

I faced the same issue while development and needed to get the hash key to test sharing on facebook, and while solving this I went through couple of issues

1- the command facebook provide to get the hash key by using openSSL command didn't give me the right hash that I got by extracting the signature from Package info with code. getting the hash by the second way was correct.

2- For some reason, In the documentation they tell you to go to developer settings and add the hash key for 'Sample App' there, I thought every hashkey for a developer should be there, and that was my mistake, every app has it's own hash keys field to add to, go to your app/settings/android.

enter image description here

well that was it.. and for the records I used openssl-0.9.8k_X64 on a Windows 7 x64 bit and it just generates a wrong hash I don't know why

I used this code to get the hash:

private void printKeyHash() {
// Add code to print out the key hash
try {
PackageInfo info = getPackageManager().getPackageInfo("YOUR PACKAGE NAME", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
Log.e("KeyHash:", e.toString());
} catch (NoSuchAlgorithmException e) {
Log.e("KeyHash:", e.toString());
}
}

but be careful that this may not also print in logs the correct keyhash, at least on my device and machine, when I debug it, in a watch it shows the correct hash just before printing the logs, but in logs it shows another hash and the first one was the correct one.

anyway you can also use a command or eclipse to view the SHA hexadecimal sequence for your key and convert it to base 64 online, there are websites that may help http://tomeko.net/online_tools/hex_to_base64.php?lang=en

Good luck

I have had this Problem for two months now. My key hashes have been pyling up to 9. Today i finally found the simple solution:

STEP 1:

Install the facebook sdk you downloaded from the facebook developer page on your phone. Don´t install the normal facebook app. Make sure you can log into facebook. Then log out.

STEP 2:

Export your app with your final release key as an apk, like you would when uploading it to the playstore.

STEP 3:

Put the Apk file on your phone via usb cable or usb stick.

STEP 4:

Install your app, using a file manager: For example https://play.google.com/store/apps/details?id=com.rhmsoft.fm

STEP 5:

Launch your app and try to log in with facebook. A dialog will open and tell you: "the key has not been found in the facebook developer console

STEP 6:

Write down the key.

STEP 7:

Put it into your facebook developer console and save. Now you are done. Anyone that downloads your app, published with earlier used keystore can log into facebook.

Enjoy

Using Debug key store including android's debug.keystore present in .android folder was generating a strange problem; the log-in using facebook login button on android app would happen perfectly as desired for the first time. But when ever I Logged out and tried logging in, it would throw up an error saying: This app has no android key hashes configured. Please go to http:// ....

Creating a Keystore using keytool command(keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -sigalg SHA1withRSA -keysize 2048 -validity 10000) and putting this keystore in my projects topmost parent folder and making a following entry in projects build.gradle file solved the issue:

 signingConfigs {
release {
storeFile file("my-release-key.keystore")
storePassword "passpass"
keyAlias "alias_name"
keyPassword "passpass"
}    }

Please note that you always use the following method inside onCreate() of your android activity to get the key hash value(to register in developer.facebook.com site of your app) instead of using command line to generate hash value as command line in some cased may out put a wrong key hash:

    public  void showHashKey(Context context) {
try {
PackageInfo info = context.getPackageManager().getPackageInfo("com.superreceptionist",
PackageManager.GET_SIGNATURES);
for (android.content.pm.Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());


String sign=Base64.encodeToString(md.digest(), Base64.DEFAULT);
Log.e("KeyHash:", sign);
//  Toast.makeText(getApplicationContext(),sign,     Toast.LENGTH_LONG).show();
}
Log.d("KeyHash:", "****------------***");
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
}

I got the same problem. I found that I used wrong hashkey. keytool printed wrong hashkey because I run command with wrong alias.
Please check your command again.It will resolve your issue

keytool -exportcert -alias "test fb sdk" -storepass android -keypass android -keystore "C:\keystore.keystore" | openssl sha1 -binary | openssl base64

If your login is working without installing facebook app and not working when facebook app is installed due to error "hash key has not match" then do following steps

1 ) Launch your app and try to log in with facebook. A dialog will open and tell you: "the key has not been found in the facebook developer console and also show the hash key.

2 ) Note down that hash key.

3 ) Put it into your facebook developer console where you first generated your api key and remove the hash key with new and save. Now you are done. Anyone that downloads your app, published with earlier used keystore can log into facebook.

  1. Check your Key hash value.
  2. Uninstall the Facebook application from your phone.
  3. Then try again using SDK.

This solved my problem.

I encountered a similar problem. The solution is surprisingly simple.

The error message looks like this:

07-05 ...... Invalid key hash. The key hash sL1***************VY= does not match any stored key hashes. Configure your app key hashes at http://developers.facebook.com/apps/150*******778
07-05 ......     at com.facebook.login.LoginManager.onActivityResult(LoginManager.java:191)

Simply log into https://developers.facebook.com , select the "Settings" tab, and add the key hash "sL1***************VY=" to the list of saved Key hashes in the Android panel.

It is looks crazy but it work

Really issue because of you privite facebook account got this app and hash key of this account does't comparable

But you musn't to faced this error with real user. But I am not sure

Eventually follow next step :

  1. Go to your private facebook account which you try to log in
  2. Then click More in app dir

enter image description here

  1. Click Settings

enter image description here

And then click cross

enter image description here

And now you can login with facebook. But next time if you log out and than will try log in again you faced with the same issue...

It is also weird...

But I don't bellieve that facebook don't know about this ...

Check your google-services.json . May be it is different one. Download your latest google-services.json and then run the app. Hope it helps.

I got simular problem. After signing and publishing my app to the google PlayStore it seems the Hash has changed. I added the new Hash (as mentioned) in the Facebook messaged to the Key Hashes in my app on developers.facebook.com/app//settings. Now it works again.

This is a case that could have possibly occurred and what solved my error:

In the https://developers.facebook.com/quickstarts after you run

OSX/Linux:

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

Windows:

keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | openssl sha1 -binary | openssl base64

When Enter keystore password: is asked you may have accidentally typed a wrong password, the default password is "android". Typing any other password will give you a different/wrong hash key. Paste the correct hash key in the Key Hashes field on your app page

This solved my problem, hope this helps whoever made this particular error that I made

You are may be using wrong password the default password for debug keystore is android

What I found was that my SHA-1 that was used to sign the app to be uploaded to the Google Playstore was not correct. I realized that my app was being signed by the Google Play Store with a different token. I followed these steps:

  1. Go to Google Play Console
  2. Click Release Management
  3. Click App Signing
  4. Convert App-Signing Certificate SHA-1 to Base64 (this will be different than your current upload certificate)
  5. Enter Base64 converted SHA-1 into my Facebook Developer dashboard settings

    I am now able to log into my app when the Facebook is downloaded on and Android device.

My problem is possibly due to the hash got wrongly generated by the openssl itself, if anyone is facing similar problem using the method provided by the facebook android guide itself.

One way to deal with this is :

  1. Get your sha1 using this tool :

keytool -exportcert -keystore path-to-debug-or-production-keystore -list -v

  1. convert it to base64 using this tool

http://tomeko.net/online_tools/hex_to_base64.php

credit :

https://github.com/facebook/react-native-fbsdk/issues/424#issuecomment-469047955

---2019----- This is how i solved this problem

  1. in android studio in right panel Gradle>App>android>signingReport copy SHA1
  2. 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.

While generating release Hash key, Note this

For Windows

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

The versions produce different hash keys, for some reason 9.8k does not work correctly... 9.8e does.

OR

Use this below flow

This is how i solved this problem Download your APK to your PC in java jdk\bin folder in my case C:\Program Files\Java\jdk1.7.0_121\bin go to java jdk\bin folder and run cmd then copy the following command in your cmd

keytool -list -printcert -jarfile yourapkname.apk

Copy the SHA1 value to your clip board 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.

For MAC

Step 1:

Generate SHA1 key by using below command
keytool -list -v -keystore Keystore path
Enter Keystore password.
Copy SHA1 Key.

Step 2:
Open this link - http://tomeko.net/online_tools/hex_to_base64.php
Paste the SHA1 Key in Hex String
Click convert button
Get the Release Keyhash in Output value

Follow these steps in order to generate the correct key hashes.

  1. Open your project in android studio and run the project.
  2. Click on Gradle menu.
  3. Select your app and expand task tree.
  4. Double click on android -> signingReport and see the magic Sample Image
  5. Result after clicking above tab Result after clicking above tab
  6. Copy the SHA1 key and browse SHA1 key to key hash
  7. After converting the SHA1 key to key hash copy the new key hash and paste it in facebook console. This will work like charm.

I am also getting the same issue when user try to Login with Facebook.

Not Working: Facebook App is Installed in Device.

Working: Facebook app is not installed

So, following Code is resolved the issue event the Facebook app is installed in device.

LoginManager.getInstance().setLoginBehavior(LoginBehavior.WEB_ONLY); //This Line Solved Issue
LoginManager.getInstance().logInWithReadPermissions(context, Arrays.asList("public_profile", "email"));

DATE UPDATED EVERY TIME I GOT UPVOTE AS I KNOW IT IS STILL VALID

DATE: 05/12/2022 (5th of Dec 2022)

This is how I solved this problem

  1. I have got the SHA1 from signingReport

(found in gradle-->app/Tasks/android/signingReport)

Copy the SHA1 value to your clipboard

like this XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX

  1. Facebook sdk requires it to be in base64 hash key so we 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 " ********************= "

  1. open https://developers.facebook.com/

  2. select your project in the setting tab, basic/Key Hashes add the generated key.

  3. don't forget to save changes.

@Ketan Ramani answer helped me but in my case, I was not using the LoginManager instead I was registering a callback on an image if you are using registerCallback on any image by making it a login button use below code

 loginButton.setLoginBehavior(LoginBehavior.WEB_ONLY);

I have tried everything on this page but no success, until i took a break, then when I continue working on this, without changing anything, it suddenly works. Maybe (just maybe) facebook needs times to register the key

This worked for me

  1. Go to Google Play Console
  2. Select Release Management
  3. Choose App Signing
  4. Convert App-Signing Certificate SHA-1 to Base64 (this will be different than your current upload certificate) using this tool: http://tomeko.net/online_tools/hex_to_base64.php?lang=en
  5. Enter Base64 converted SHA-1 into your Facebook Developer dashboard settings and try again.

your Google Play SHA-1

For signing the developer build, you will use the keystore and key generated by Android Studio. You can retrieve this with the following command:

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

Thanks

In the right side of Android Studio go to Gradle -> Tasks -> android -> signingReport and run it. Copy the SHA-1 key and transform it into base64 using this, and then add the converted base64 hash to your app in the Facebook Developer Console. If you want to use a release hash run this in the command line:keytool -exportcert -alias YOUR_KEYSTORE_ALIAS -keystore YOUR_KEYSTORE | openssl sha1 -binary | openssl base64 Where YOUR_KEYSTORE is the path to the .keystore or .jks that you used as signinConfig for your release variant and YOUR_KEYSTORE_ALIAS is the alias which you gave when you created the keystore. If you do not remember the alias you can run keytool -v -list -keystore YOUR_KEYSTORE and see all the info about the keystore

On Debug

Copy Paste This code inside OnCreate method

       try {
PackageInfo info = getPackageManager().getPackageInfo(
getApplication().getPackageName(),
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (PackageManager.NameNotFoundException e) {
Log.d("KeyHash e1",e.getLocalizedMessage() +"");
} catch (NoSuchAlgorithmException e) {
Log.d("KeyHash e2", e.getLocalizedMessage() +"");
}

Open Logcat and Filter/find 'D/KeyHash:'

D/KeyHash: D5uFR+65hafzotdih/dOfp14FpE=

Then Open https://developers.facebook.com/ and Open YourApp/Setting/Basic
Scroll down to Android Section Then Paste the Key Hashes and Save

Just run command adb logcat | grep hash and look for something like Key hash ABCDEFGH1234= does not match any stored key. Now save this hash on your fb developer console.

I have same problem when I so facebook integration, and I solved this error by this steps:

  1. open android folder(File/open/yourFlutterProject/android) in your flutter project
  2. now you can see gradle field in right-side top penal -------Gragle Image
  3. do this steps(gradle/android/app/tasks/android/signingReport) and click it.
  4. now you can see your project SHA-1 key, note it.
  5. now open this site(Site Link) and convert SHA-1 to keyhash and you get your keyhash value, note it.
  6. not update/change this keyhash with currunt keyhash in your developer.facebook console
  7. now its run perfect.

What worked in my case:

The best solution is to get your APK file, Use the keytool to get your app's signature as follows:

C:\Program Files\Android\jdk\microsoft_dist_openjdk_1.8.0.25\bin> ./keytool -list -printcert -jarfile myapp.coolapp.apk

In my case, my apk was placed in the same directory as the keytool, I later deleted it. After running the above command, you have a list of keys, copy the SHA1 key Convert it to base64 using this tool Copy the Base64 conversion, Go to facebook dev portal, navigate to your app, then "settings/basic" Then go to the key hashes section. Paste the Base64 hash there, and facebook login will work just fine.

Here is an article that explains these steps in detail:

For Windows Only:

At first I used "openssl-0.9.8k_X64.zip" for generate hash of key. This problem appears.

Then I used the openssl version "openssl-0.9.8e_X64.zip" in windows. Then the problem solved.

https://code.google.com/archive/p/openssl-for-windows/downloads

I think most of us having same problem.

For me what eventually worked was to use the debug.keystore that is stored inside the android/app folder. So basically running the keytool command from the app folder like that:

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

The password is: android

I faced this issue. Then I uninstalled my Facebook App. Then it is opening with my default browser. Then the login/signup was succeeded via facebook.