SDK Command Facebook Android - Key hash

Asked

Viewed 10,977 times

6

I’m doing the tutorial on SDK of Facebook for Android and I didn’t understand this part, which talks about hashes key to development environments.

Print do Tutorial

Commando:

keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | openssl sha1 -binary | openssl base64

Where should I execute this command? I tried CMD but failed.

  • Which error occurred ?

  • "'keytool' is not recognized as an internal & #Xa; or external command, a operable program, or a batch file."

2 answers

9

There are a million ways to retrieve this Key Hash.

It serves to identify that only your project is accessing the user’s Facebook information, as security even.

I always broke my head to get that key back, but I learned a very simple way to do it.

Within the onCreate method, enter this code:

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

}
catch (NoSuchAlgorithmException e) {

}

Now run your application, on your Logcat (Android Monitor), will appear a code more or less like this:

KeyHash: nzM5O1NWEmtflcC3vDK2lx3CwcM=

All these numbers and letters are your Hash Key, including the sign of =, then you put it on the Facebook control panel, so it recognizes your application.

  • Remembering that this method only serves for the Debug procedure , ie, development. Correct ?

8


Hello, you must inform the path where is the keytool and openssl on your computer. In my case is on:

C: Program Files Java jdk1.8.0_91 bin keytool.exe

C: Openssl-Win64 bin openssl.exe

now just replace it, it will be like this:

"C: Program Files Java jdk1.8.0_91 bin keytool.exe"-exportcert -alias androiddebugkey -Keystore %HOMEPATH%. android debug.Keystore | "C: Openssl-Win64 bin openssl.exe" sha1 -Inary | "C: Openssl-Win64 bin openssl.exe" Base64

Once done, you need to enter a password, which by default is android.

Ready! Your hash will appear, you must copy everything including the =

Browser other questions tagged

You are not signed in. Login or sign up in order to post.