5

On https://developers.facebook.com/docs/android/getting-started/facebook-sdk-for-android/ we show how to get the key hash but i don't know what i can to do with" keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%.android\debug.keystore | openssl sha1 -binary | openssl base64". On the website we talk about Java's keytool utility but i don't know what is it? Please I want to create my facebook app for android i don't know how all of this work. I need someone to help me step by step. Thanks you for Advance.

Ange Bagui
  • 51
  • 1
  • 1
  • 3

5 Answers5

4

Keytool is part of Java JDK. The keytool command you mentioned will output a base64, sha1 encrypted representation of your debug key. Your app is signed with this debug key each time you compile it. Facebook uses this key to verify that your computer compiled the app. So in the Facebook Manage App interface, you would put the output of the keytool command.

If you run into trouble running the command, it has most likely to do with incorrect paths. Try:

"C:\Program Files\Java\jdk1.6.0_33\bin\keytool.exe" -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | "C:\Users\A\Downloads\openssl-0.9.8h-1-bin\bin\openssl.exe" sha1 -binary | "C:\Users\A\Downloads\openssl-0.9.8h-1-bin\bin\openssl.exe" base64

Where you change the paths in quotes to the paths of openssl.exe and keytool.exe on your computer. (You might have to download openssl first)

ln e
  • 945
  • 1
  • 6
  • 16
  • In the Terminal i have writen ***** C:\Program Files\Java\jdk1.7.0_40\bin\keytool.exe -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | C:\OpenSSL-Win32\bin\openssl.exe sha1 -binary | C:\OpenSSL-Win32\bin\openssl.exe base64 ***** but i see error please help me. – Ange Bagui Oct 27 '13 at 23:48
  • You should not remove the quotes around the paths. (See my example) – ln e Oct 27 '13 at 23:53
3

follow these steps: 1. Set path on your cmd.

    C:\Program Files\Java\jdk1.7.0_03\bin
  1. Then download openssl-0.9.8k_WIN32. Paste it into your C: folder.
  2. Use following command

     C:\Program Files\Java\jdk1.7.0_03\bin\keytool -export -alias myAlias -keystore            
     C:\Users\Admin\.android\debug.keystore | C:\openssl-0.9.8k_WIN32\bin\openssl enc -a -e
    

    4.It will ask for password.put PASSWORD = android

  3. You will get your hashkey. for more info visit: [ http://android-developer-helpdesk.blogspot.com/2014/04/hash-key-generation.html ]
Zied R.
  • 4,831
  • 2
  • 35
  • 62
3

first of all check your system that it is 64 bit or 32 bit.

if it is 32 bit then gives the following command

keytool -export -alias myAlias -keystore C:\Users\monue\.android\debug.keystore | C:\openssl\bin\openssl sha1 -binary | C:\openssl\bin\openssl enc -a -e

and if it is 64 bit then gives the following command

"C:\Program Files\Java\jdk1.6.0_33\bin\keytool.exe" -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | "C:\Users\A\Downloads\openssl-0.9.8h-1-bin\bin\openssl.exe" sha1 -binary | "C:\Users\A\Downloads\openssl-0.9.8h-1-bin\bin\openssl.exe" 

base64

Hamad
  • 4,906
  • 13
  • 32
  • 65
Monu
  • 31
  • 2
2

No matter the computer, the easiest way to do this is simply by downloading (openssl) - (https://code.google.com/p/openssl-for-windows/downloads/list) and placing it in a new folder on the c Drive like so .... example {C:\openssl}

Now you command prompt should look something like this when looking for release key (just switch locations to debug keystore or vice versa!

Please remove all quotation marks before pasting into command prompt...

keytool -exportcert -alias "name of your keystore goes here" -keystore "location wher your keystore file is" | C:\openssl\bin\openssl.exe sha1 -binary | C:\openssl\bin\openssl.exe base64

kleopatra
  • 49,346
  • 26
  • 88
  • 189
1

If you are using to android studio as developing platform than it it will be easy to get Key Hash for Facebook.

1 : Create a java file MyApplication.java .

2 : Paste the below code in it.

public class MyApplication extends MultiDexApplication {

public void onCreate(){
    super.onCreate();
    PrintKeyHash();

}

public void PrintKeyHash(){
    try{
        PackageInfo info = getPackageManager().getPackageInfo("com.bhunnu.nearveg", PackageManager.GET_SIGNATURES);
        for (Signature signature: info.signatures){
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.e("Your System KEYHASH : ", Base64.encodeToString(md.digest(), Base64.DEFAULT));
        }
    }catch (PackageManager.NameNotFoundException e){

    }catch (NoSuchAlgorithmException e){

    }
}

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}

}

3 : now open your manifests file and in application tag write android:name=".MyApplication".

same as below in AndroidManifest.xml

 <application
    android:allowBackup="true"
    android:icon="@drawable/icon1"
    android:label="@string/app_name"
    android:name=".MyApplication.java"
    android:theme="@style/AppTheme">

If you already use name like android:name="android.support.multidex.MultiDexApplication" then also replace it because i have used extends multidexing in MyApplication.java file.

you are using any name than also once replace it by MyApplication.java file after getting to Hash you can use your previous file name.

Bhunnu Baba
  • 1,554
  • 11
  • 19