Google Play App Signing - KeyHash Mismatch

Rocé Tarentula picture Rocé Tarentula · Jun 28, 2017 · Viewed 15.4k times · Source

I'am using the new Google Play App Signing to sign my application and there is a mismatch key-hash.

I integrated Facebook Login in my app and it said keyhash invalid. The keyhash release of my APK is different of the keyhash release created by the process of Google Play App Signing.

EDIT : Step i did:

1) Created a jks keystore file.

2) Created a apk release signed with the jks file.

3) Imported the APK in Google Console Developer, with the subscription to Google Play App Signing which modify the signed key.

4) Once online, i download and open the app, Facebook initialization say : Invalid Key hash

When i check the hashkey in the app via the code below, the hash key is different of the invalid hashkey said by Facebook:

  try {
        PackageInfo info = getPackageManager().getPackageInfo(
                "com.package",
                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 (PackageManager.NameNotFoundException e) {

    } catch (NoSuchAlgorithmException e) {

    }

Even if i put the hashkey said by Facebook in the Facebook dashboard, it don't work. It seems Google Play App Signing modify the hashkey during signing process. Do you have an idea to resolve it?

Answer

Neeraj Sewani picture Neeraj Sewani · Oct 12, 2018

You have to use the SHA-1 key generated by Google. Following steps would fix it.

1). Go to Google console => Release Management => App signing => App signing certificate.

2). Copy SHA-1 certificate from there and as it's in hexadecimal and since Facebook needs it in base64 so use the command shown in step 3

3).echo SHA-1 key from step-2 (Hexadecimal) | xxd -r -p | openssl base64
This command won't work in command prompt use bash on windows or git cli.

4). Paste the base64 key in Facebook console => Settings => basic => key hashes