32

I am using facebook sdk for login into my application. The application runs fine on HTC devices. The application also works fine on Samsung devices if there is no facebook app pre installed.

But if there is already facebook app on mobile and then the user installs my app, the user is never logged in. From what I know, I think this might be a problem of single sign on, and I think this is somewhat related with generating proper application hash key, and using the hash key in facebook application which I used to log into the mobile app.

Please guide me how to create the hash key. I am running ubuntu 10.4.

When I run this command in terminal :-

keytool -exportcert -alias <your keystore alias name>.keystore -keystore ~/.android/<your keystore name>.keystore | openssl sha1 -binary | openssl base64

I am never prompted for password, though I am given the hash key.

Arnaud
  • 6,339
  • 8
  • 47
  • 64
abhishek
  • 1,414
  • 7
  • 39
  • 68
  • [Here][1] you can get your answer, it also helped me. http://stackoverflow.com/a/12405323/2331725 [1]: http://stackoverflow.com/a/12405323/2331725 – Ashher Alam Jul 02 '13 at 09:31
  • To generate hashkey[Simple Method is here][1] [1]: http://stackoverflow.com/questions/5306009/facebook-android-generate-key-hash/12405323#12405323 – karthik Nov 14 '13 at 20:00
  • I have generated the key hash but don't know where to put that key, would you guide me? I'm running android studio on Ubuntu. – Apurva Oct 08 '15 at 18:31
  • Did you find the mistake? Exactly which command helped you?I am facing the same problem. – Shruti May 08 '17 at 09:22

6 Answers6

62

Try this:

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

I hope you will get it. I just checked it and I got the prompt for password.

Awais Qarni
  • 14,876
  • 22
  • 72
  • 134
Lavanya
  • 3,953
  • 6
  • 30
  • 61
46

You can use this code block to generate hash key. Put this code block in your onCreate() method.

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("Your Tag", Base64.encodeToString(md.digest(), Base64.DEFAULT));
            }
    } catch (NameNotFoundException e) {

    } catch (NoSuchAlgorithmException e) {

    }
ACengiz
  • 1,245
  • 17
  • 23
  • Worked perfectly for me...did also try below command to get the same result: keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64 – Vinay Oct 17 '13 at 13:17
  • 2
    this is it. remember to change "Your package name" with your package name ;) – OWADVL Mar 24 '14 at 20:58
  • 3
    Does this code produce same hash key in both: debug and release? – Kostadin Mar 31 '14 at 13:00
  • I have generated the key hash but don't know where to put that key, would you guide me? I'm running android studio on Ubuntu. – Apurva Oct 08 '15 at 18:32
4

If it's not prompting you for password, then first open your terminal and type :

sudo apt install openjdk-8-jre-headless

And then follow the regular way, just type:

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

For password put: android You are all done.

This answer is for debug purpose only, for release purpose use your .jks file to generate hash key.

Rishabh Chandel
  • 695
  • 10
  • 26
3

Just give the command as:

keytool -exportcert -alias androiddebugkey -keystore debug.keystore

and give the keystroke password or android or enter

Here you have to go to the directory structure until ".android" then run this commnad.In general the path is C:\Users\User-name\.android>.

Fabian Lauer
  • 5,893
  • 3
  • 20
  • 31
rishi
  • 31
  • 1
  • I have generated the key hash but don't know where to put that key, would you guide me? I'm running android studio on Ubuntu. – Apurva Oct 08 '15 at 18:32
2

Check three parts in your environment.

  1. where is "debug.keystore"?

    find / -name "debug.keystore"

    if you can't find it, check you eclipse or ADT.

  2. what is alias name?

    keytool -list -v -keystore "PATH_TO_DEBUG_KEYSTORE"

  3. Check if installed openssl

    openssl

If everything is ready, it should prompt for password

Lavanya
  • 3,953
  • 6
  • 30
  • 61
Kislingk
  • 1,199
  • 12
  • 20
  • I have generated the key hash but don't know where to put that key, would you guide me? I'm running android studio on Ubuntu. – Apurva Oct 08 '15 at 18:32
  • after entering the password for release apk showing chines language please help me – Harsha Sep 29 '16 at 07:18
0
C:\openssl\bin>keytool -exportcert -alias aliasName -keystore "C:\Users\s\.android\debu
g.keystore" | "C:\openssl\bin\openssl" sha1 -binary | "C:\openssl\bin\openssl" b
ase64
Enter keystore password:  android
GEYtOJobR4NzuxX4iOl/yR6sla4=
CherryDT
  • 13,941
  • 2
  • 31
  • 50