3

I am trying to implement Facebook into my app to allow things like sending stuff to the user's wall, updating status', etc.

So after downloading the stuff I was told to get a key using the keystore file. I decided to be brave and create my own keystore file (for publishing stuff later) and did so successfully.

After creating the file though I am having all sorts of problems trying to retreieve a key from it, i entered the command via keytool/command prompt and it asked me for my keystore password...

After entering the password i set in the first place, I am getting nothing but wierd ascii symbols and letters and my keystore details also in the middle of it. What is going wrong??

UPDATE: Ok, I am aware you may need to use OpenSSL to display the text correctly. I have installed OpenSSL but how do I use it to get the Hash code?

1
  • Also, I have setup a dev page on FB which has given me app ID and secret, do I still need to do this keytool thing ?
    – Jamie
    Feb 16, 2011 at 11:30

4 Answers 4

4
  1. Download Openssl from: http://code.google.com/p/openssl-for-windows/downloads/list

  2. Make a openssl folder in C drive

  3. Extract Zip files into openssl folder

  4. check that the directory the keytool executable is in is on your path. (For example, on my Windows 7 machine, it's in C:\Program Files (x86)\Java\jre6\bin.)
  5. open cmd and paste:

    keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | C:\openssl\bin\openssl sha1 -binary | C:\openssl\bin\openssl base64

type password android if need you receive your hash code

1
  • Welcome to SO. Your answer is nearly identical to the previous answer for this question, which was posted over a year ago. If you were adding a piece of missing information, please consider posting a comment on the existing answer instead of creating a new one.
    – acj
    Nov 15, 2012 at 3:47
3

I always use this method under Linux, because it fails in the original way:

keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore > key.out
cat key.out | openssl sha1 -binary > key.bin
cat key.bin | openssl base64

You will get the key you need to enter on page mobile, android section of your Facebook apllication. Every time you use different keytore to sign your app, you need to change the key on the facebook page also.

0
0

The best method.

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

Some times the openssl provide the wrong keyhash.

0

you can use code below to get the Hash key :

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) {
   Log.e("name not found", e.toString());
  } catch (NoSuchAlgorithmException e) {
   Log.e("no such an algorithm", e.toString());
  }

Reference :

http://limbaniandroid.blogspot.com/2013/04/how-to-get-hash-key-for-integarte.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.