Introduction
Here is an example of Getting Key Hash for Facebook Console. Key Hash is used by the Facebook console to identify your application. There can be two different keys has for the same application one is for the development and another one is for the release mode. When you are working with the development mode then you can use development Key Hash but for the release version, you have to provide the release Key Hash else Facebook login will not work.
Getting Key Hash for Facebook Console
Though it is a very small topic for some of the people but a very big issue for some people who are facing “Facebook error: SERVER_ERROR: [code] 1349195 [message]: The key hash does not match any stored key hashes. Go to https://developers.facebook.com/docs/facebook-login/android for more information. [extra]: ” issue.
Generating a Key Hash is very simple according to Facebook and the rest of the internet but become annoying when Facebook throws the “key hash does not match” error so I decided to make a separate example for it as I have personally felt this problem for hours. So here is my solution to generate Key Hash.
Option 1: Follow the method shared by the Facebook developer console
You can follow the way Facebook described here where you can run the following command to generate Key Hash
1. For Mac/Linux
Debug Key Hash
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64
Release Key Hash
keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | openssl sha1 -binary | openssl base64
2. For the windows you need to download the OpenSSL else you will find the following error.
Debug Key Hash
After downloading the OpenSSL you can unzip it in your C directory and run command (Before running please check the file path once)
keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | C:\openssl\bin\openssl.exe sha1 -binary | C:\openssl\bin\openssl.exe base64
keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | PATH_TO_OPENSSL_LIBRARY\bin\openssl sha1 -binary | PATH_TO_OPENSSL_LIBRARY\bin\openssl base64
This was the first and known way. If you are lucky enough then you will get the hash and it will also work :p but in some cases, it provides lots of issues and I was the one in that some case.
So finally I tried to find the permanent solution and come up with a new way.
Option 2: Generate Key Hash using SHA1
Yes, you can also generate the Key Hash using the SHA1 of your project. Key Hash is nothing new it is just the encoded format of your unique SHA1 which Facebook prefers. If you are using the Debug SHA1 then this Key Hash will become the Debug Key Hash and if you are using the Release SHA1 then it will become the Release Key Hash. So let’s see how we can do that. If you don’t have any idea how to get the SHA1 Fingerprint then you can go through the example How you can get the SHA1 Fingerprint for Android. After getting the SHA1 you have to open a link tomeko.net where you will see the option to insert SHA1 and it will convert your SHA1 into Key Hash.
This is a 100% recommended solution for the KeyHash but if you are still facing the issue then please let me know in the comment below.
Hope you liked it. 🙂
Solution 2 worked. Thank you for that. I was very fed up of that. I have tried to generate the key from every different way. Please include the password generation method too. Each time you run the command it asks for the password and when you enter any password it generates the Key Hash though they are always different and I tried different hashes but nothing worked. Finally, solution2 worked successfully. Thank you. thank you very much. 🙂
It is the only reason I have posted this post. 🙂
Happy it worked for you.
Brother, I don’t understand how to say thank you. Solutions 2 worked. Thank you so much.
And one thing I don’t understand why hash key not working which we generate from cmd. If you know please do let me know.
I’m using expo , so I get facebook key hash with expo fetch:android:hashes ,
the app will be signed with a different key after publishing to the store , so you need to get SHA1 Fingerprint from google console and convert it to key hash by tomeko.net , this notice for future visitors
Yo, method2 worked better. Thank you so much sir. Much love
In my case the hash generated by method 1 was matching the hash generated by method 2 for the SHA-1 taken from App signing section (Upload key certificate) on Google Play Console.
Thank you so much. Option 2 is worked successfully.
I almost gave up on every other method, but your Method 2 worked. Thank you so much.
Nice to know that 🙂