开发者

keytool with Android Facebook SDK

开发者 https://www.devze.com 2023-03-15 23:22 出处:网络
I just want some confirmation. I\'m developing on windows I\'m attempting to integrate facebook into an app and the SDK documentation says I need to \'export a signature\'

I just want some confirmation.

I'm developing on windows

I'm attempting to integrate facebook into an app and the SDK documentation says I need to 'export a signature'

From here: http://developers.facebook.com/docs/guides/mobile/#android

So it says run this command:

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

First I had to download openssl: OpenSSL

Now the command above, I assume should be converted to:

"C:\path\to\java\keytool" -exportcert -alias your_alias -keystore "C:\path\to\your\keystore\keystore.name" | "C:\path\to\openssl_install\bin\openssl" sha1 -binary |"C:\path\to\openssl_install\bin\openssl" base64
  • So you want the keytool that is installed in your latest Java install folder?
  • You want the alias to be the name of the alias you use for a normal apk creation in eclipse?
  • You want the keystore to be the one you use when exporting android apps?
  • You want openssl to be the one you just installed

So once I've done this it asks for a password: (it shows the password as I'm typing it)

If I enter a correct password I get

'zR2tey1h9kq开发者_高级运维PRSW/yEYEr0ruswyD=' (changed for public)

but if I enter an incorrect password it still returns me a code in the form of

'ga0RGNYHvTR5d3SVDEfpQQAPGJ1='?

So yeah, was just looking for a confirmation that I'm doing the right thing, and this is the output expected


the best way to get your hash is by running the following code:

try {
            PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
            for (Signature signature : info.signatures) {
                MessageDigest md;

                    md = MessageDigest.getInstance("SHA");
                    md.update(signature.toByteArray());
                    String something = new String(Base64.encode(md.digest(), 0));
                    Log.e("hash key", something);
        } 
        }
        catch (NameNotFoundException e1) {
            // TODO Auto-generated catch block
            Log.e("name not found", e1.toString());
        }

             catch (NoSuchAlgorithmException e) {
                // TODO Auto-generated catch block
                 Log.e("no such an algorithm", e.toString());
            }
             catch (Exception e){
                 Log.e("exception", e.toString());
             }

when extracting the hash with windows cmd,git bash or cygwing terminal, the three tools give different result.

the most accurate is the code above


yes you are doing it in a right way i think.i also execute this command and put this hash in my fb app and its works properly.


Answer to your question below:

So once I've done this it asks for a password: (it shows the password as I'm typing it)

If I enter a correct password I get

'zR2tey1h9kqPRSW/yEYEr0ruswyD=' (changed for public) but if I enter an incorrect password it still returns me a code in the form of

'ga0RGNYHvTR5d3SVDEfpQQAPGJ1='? So yeah, was just looking for a confirmation that I'm doing the right thing, and this is the output expected

keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64 has three commands feeding output of preceding command to following command.

  1. keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore
  2. openssl sha1 -binary
  3. openssl base64

When incorrect keystore password is given, first command generates error but that won't be displayed as that would be input to second command and different hash is generated. Only run first keytool command (keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore) to confirm your keystore password and if it is right. If password is incorrect, similar to output below will be displayed.

> keytool -exportcert -alias androiddebugkey -keystore 

~/.android/debug.keystore Enter keystore password:
keytool error: java.io.IOException: Keystore was tampered with, or password was incorrect

Provide android to answer for Enter keystore password: for prompt if android debug hash is generated. Default password for android debug keystore is android

Command could also have written to catch error from keytool command to see if command 1 returned error before running command 2.

So you want the keytool that is installed in your latest Java install folder?

You want the alias to be the name of the alias you use for a normal apk creation in eclipse?

You want the keystore to be the one you use when exporting android apps?

You want openssl to be the one you just installed?

Yes to all of questions above. PATH could be setup not to type full path for keytool and openssl.

0

精彩评论

暂无评论...
验证码 换一张
取 消