2

I am trying to implement login using Facebook. I have problem with hash keys. First of all I have installed OpenSSL into C:\OpenSSL\

On Windows 7, I run cmd as adminstrator. Went into jdk's bin folder:

 cd C:\Program Files\Java\jdk1.7.0_45\bin

Try 1:

keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | "C:\OpenSSL\bin\openssl" sha1 -binary |"C:\OpenSSL\bin\openssl" base64

Entered password: android

Result: 1234567890ab (12 character). But documentation says :

This command should generate a 28 characher string. Copy and paste this Release Key Hash into your Facebook App ID's Android settings.

Try 2:

keytool -exportcert -alias androiddebugkey -keystore "C:\Documents and Settings\Administrator.android\debug.keystore" | "C:\OpenSSL\bin\openssl" sha1 -binary |"C:\OpenSSL\bin\openssl" base64

Password: not asking password

Result: 1234567890abcdefghijklmnopqr (28 character string). I have entered this into app page on Facebook developers. Logged into account successessfully. It is getting my name from Facebook. Logged out, tried to log into again. Getting this error on mobile device:

Invalid key hash. The key hash 0987654321abcdefghijklmnopqr (28 character string different from I generated) does not match any stored key hashes. Configure your app key hashes at http://developers.facebook.com/apps/1234567890123456

Try 3:

Followed this solution: https://stackoverflow.com/a/12405261/2255924

Result: I am getting something unreadable (abracadabra) but first character is similar to try 2's hash key.

What I am doing wrong? How to solve this problem?

Community
  • 1
  • 1
Joe Rakhimov
  • 4,713
  • 9
  • 51
  • 109

2 Answers2

1

just execute this code in your app and you will get KeyHash In LogCat

try
{
    PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
    for (Signature signature : info.signatures) 
    {
        MessageDigest md = MessageDigest.getInstance("SHA");
        Log.e("MY KEY HASH:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
    }
} 
catch (NameNotFoundException e)
{

} 
catch (NoSuchAlgorithmException e) 
{

}
Kirtan
  • 1,782
  • 1
  • 13
  • 35
  • This code is for checking the hashKey not to use for generation.https://developers.facebook.com/docs/android/getting-started follow this link. – Piyush Nov 11 '14 at 04:57
  • @Kirtan, thank you for your instant answer, it is giving hash key. I entered it. Unfortunately, i am getting error: Invalid key hash. The key hash 0987654321abcdefghijklmnopqr (28 character string different from I generated) does not match any stored key hashes. Configure your app key hashes at http://developers.facebook.com/apps/1234567890123456 – Joe Rakhimov Nov 11 '14 at 04:59
1

1.First you need to download openssl then use following command.It wiil definately work for you.

 C:\Program Files\Java\jdk1.7.0_71\bin>keytool -exportcert -alias androiddebugkey
     -keystore C:\Users\AJAY SUNDRIYAL\.android\debug.keystore | "C:\Users\AJAY SUND
    RIYAL\Downloads\bin\openssl.exe" sha1 -binary | "C:\Users\AJAY SUNDRIYAL\Downloa
    ds\bin\openssl.exe" base64


Note->
  1.C:\Users\AJAY SUNDRIYAL\.android\debug.keystore  :  this is your debug.keystore path.
  2.C:\Users\AJAY SUNDRIYAL\Downloa
        ds\bin\openssl.exe   : This is path of openssl.exe that you have downloaded from net.
SANJAY GUPTA
  • 1,564
  • 13
  • 21