简体   繁体   English

Android Facebook SDK的keytool

[英]keytool with Android Facebook SDK

I just want some confirmation. 我只想要一些确认。

I'm developing on windows 我正在开发Windows

I'm attempting to integrate facebook into an app and the SDK documentation says I need to 'export a signature' 我正在尝试将facebook集成到应用程序中,SDK文档说我需要'导出签名'

From here: http://developers.facebook.com/docs/guides/mobile/#android 从这里: 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 首先我必须下载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? 那么您想要安装在最新Java安装文件夹中的keytool吗?
  • You want the alias to be the name of the alias you use for a normal apk creation in eclipse? 您希望别名是您在eclipse中用于正常apk创建的别名的名称吗?
  • You want the keystore to be the one you use when exporting android apps? 您希望密钥库是导出Android应用程序时使用的密钥库吗?
  • You want openssl to be the one you just installed 您希望openssl成为您刚刚安装的那个

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) 'zR2tey1h9kqPRSW / yEYEr0ruswyD ='(公开更改)

but if I enter an incorrect password it still returns me a code in the form of 但如果我输入的密码不正确,它仍然会以一种形式返回给我一个代码

'ga0RGNYHvTR5d3SVDEfpQQAPGJ1='? '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. 当使用windows cmd,git bash或cygwing终端提取哈希时,这三个工具会给出不同的结果。

the most accurate is the code above 最准确的是上面的代码

是的,你是以正确的方式做我认为。我也执行此命令,并将此哈希放在我的fb应用程序中,它的工作正常。

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 'zR2tey1h9kqPRSW / yEYEr0ruswyD ='(已公开更改)但是如果我输入的密码不正确,它仍然会返回一个代码形式的代码

'ga0RGNYHvTR5d3SVDEfpQQAPGJ1='? '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 keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64 has three commands feeding output of preceding command to following command. keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64有三个命令将前一个命令的输出提供给下面的命令。

  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. 只运行第一个keytool命令( keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore )以确认您的密钥库密码以及它是否正确。 If password is incorrect, similar to output below will be displayed. 如果密码不正确,将显示类似于下面的输出。

> keytool -exportcert -alias androiddebugkey -keystore 

~/.android/debug.keystore Enter keystore password: 〜/ .android / debug.keystore输入密钥库密码:
keytool error: java.io.IOException: Keystore was tampered with, or password was incorrect keytool错误:java.io.IOException:Keystore被篡改,或密码不正确

Provide android to answer for Enter keystore password: for prompt if android debug hash is generated. 提供android来回答Enter keystore password:如果生成android debug hash则提示。 Default password for android debug keystore is android android debug keystore的默认密码是android

Command could also have written to catch error from keytool command to see if command 1 returned error before running command 2. 命令也可以编写以捕获来自keytool命令的错误,以查看在运行命令2之前命令1是否返回错误。

So you want the keytool that is installed in your latest Java install folder? 那么您想要安装在最新Java安装文件夹中的keytool吗?

You want the alias to be the name of the alias you use for a normal apk creation in eclipse? 您希望别名是您在eclipse中用于正常apk创建的别名的名称吗?

You want the keystore to be the one you use when exporting android apps? 您希望密钥库是导出Android应用程序时使用的密钥库吗?

You want openssl to be the one you just installed? 你想openssl成为你刚刚安装的那个吗?

Yes to all of questions above. 对以上所有问题都是肯定的。 PATH could be setup not to type full path for keytool and openssl. PATH可以设置为不键入keytool和openssl的完整路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM