Stolen Skull
Stolen Skull

Reputation: 25

Invalid Key hash Android

I'm using facebook SDK for facebook login into my app. I have generated the key using the following command

keytool -exportcert -alias androiddebugkey -keystore "C:\Users\ic
as2\.android\debug.keystore" | "C:\openssl\bin\openssl" sha1 -binary |"C:\openss
l\bin\openssl" base64

Generated key was

mW3....................CQc4=

Error i'm getting is

Invalid key hash. The key hash bMWwxx.................8BE does not match any stored
key hashes. Configure your app key hashes at http://developers.facebook.com/app/appID

Thanks in advance.

Upvotes: 0

Views: 661

Answers (1)

Illegal Argument
Illegal Argument

Reputation: 10338

You dont need to generare the keyhash from command line. You can try following code:

// Add code to print out the key hash
try {
    PackageInfo info = getPackageManager().getPackageInfo(
            "com.facebook.samples.hellofacebook", //your unique package name here
            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));// this line  gives your keyhash
        }
} catch (NameNotFoundException e) {

} catch (NoSuchAlgorithmException e) {

}

Alternately facebook native app will show key-hash along with the error. You could type that too.

Upvotes: 3

Related Questions