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: 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.
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. 🙂