Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SDK for Android:How facebook check the Hash key?

When we want to use Facebook SDK for Android as our SSO solution, we need to put our Android application signature into our Facebook application settings (Step 5 of Facebook sdk for android).

And that signature should be generated by running the keytool that comes with the Android SDK.

I am curious how facebook verify this signature?

like image 562
hellotli Avatar asked Apr 11 '13 09:04

hellotli


People also ask

How do I get the key hash on Facebook?

Go to the Facebook Developer site. Log into Facebook and, using the dropdown menu in the top-right, go to Developer Settings: In your developer settings, select Sample App from the menu, and add and save your key hash into your profile: You can add multiple key hashes if you develop with multiple machines.

How do I configure app key hashes on Facebook?

Steps : Go to facebook developer's page : https://developers.facebook.com/ Open the App tabs and than click the Setting. Paste the generate hashkey on HashKey's field = If you don't have it yet, get your key hash part of code.


1 Answers

After more than one year, I think I'd better answer my question.

Android's app can get other app's signature by:

public String WriteSignature(String packageName)
{     
   PackageManager pm = this.getPackageManager();
   String sig = ""; 
   PackageInfo pi = null;
   try {
       pi = pm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
   } catch (NameNotFoundException e1) {
       e1.printStackTrace();
   }

   try {
       for (Signature signature : pi.signatures) {
           MessageDigest md = MessageDigest.getInstance("SHA");
           md.update(signature.toByteArray());
           sig = Base64.encodeToString(md.digest(), Base64.DEFAULT);
           Log.d(ACTIVITY_TAG, sig);
       }
   } catch (NoSuchAlgorithmException e) {
       e.printStackTrace();
   }

   return sig;
}
like image 164
hellotli Avatar answered Oct 15 '22 22:10

hellotli