1

I am using facebook login feature in my android application and tried the documentation to generate hash key but it creates wrong hash key

Code I refered from facebook documentation

keytool -exportcert -alias androiddebugkey -keystore "C:\Users\USERNAME\.android\debug.keystore" | "PATH_TO_OPENSSL_LIBRARY\bin\openssl" sha1 -binary | "PATH_TO_OPENSSL_LIBRARY\bin\openssl" base64

In my app when I login it shows keys does not match.

Sachin Soma
  • 3,432
  • 2
  • 10
  • 18

1 Answers1

-2

Use this method in your OnCreate method.

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

If you run the application in debug mode you will get hash key for debug version in log.

For development version you have to create a release apk , run that apk on your device and you will get your key in log.

Sachin Soma
  • 3,432
  • 2
  • 10
  • 18