java 带有 Android Facebook SDK 的 keytool
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6484561/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
keytool with Android Facebook SDK
提问by Blundell
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?
- 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
- 那么您想要安装在最新 Java 安装文件夹中的 keytool 吗?
- 您希望别名是您用于在 eclipse 中创建普通 apk 的别名的名称吗?
- 您希望密钥库是您在导出 Android 应用程序时使用的密钥库吗?
- 您希望 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
所以是的,只是想确认我在做正确的事情,这是预期的输出
采纳答案by Ritesh
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.
是的,我认为您以正确的方式执行此操作。我也执行此命令并将此哈希值放入我的 fb 应用程序中,并且它可以正常工作。
回答by Mina Samy
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
最准确的是上面的代码
回答by Baha
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
因此,一旦我完成此操作,它就会要求输入密码:(它会在我输入时显示密码)
如果我输入正确的密码,我会得到
'zR2tey1h9kqPRSW/yEYEr0ruswyD='(已更改为公开)但如果我输入了错误的密码,它仍会以以下形式返回一个代码
'ga0RGNYHvTR5d3SVDEfpQQAPGJ1='?所以是的,只是想确认我在做正确的事情,这是预期的输出
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
有三个命令将前面命令的输出馈送到后面的命令。
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
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 命令 ( keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore
) 以确认您的密钥库密码以及它是否正确。如果密码不正确,将显示类似于下面的输出。
> keytool -exportcert -alias androiddebugkey -keystore
~/.android/debug.keystore
Enter keystore password:
keytool error: java.io.IOException: Keystore was tampered with, or password was
incorrect
~/.android/debug.keystore 输入密钥库密码:
keytool 错误:java.io.IOException:密钥库被篡改,或密码不正确
Provide androidto answer for Enter keystore password:
for prompt if android debug hash is generated. Default password for android debug keystore is android
如果生成了 android 调试哈希,则提供android来回答Enter keystore password:
提示。android 调试密钥库的默认密码是android
Command could also have written to catch error from keytool command to see if command 1 returned error before running command 2.
命令也可以写入以从 keytool 命令捕获错误,以查看命令 1 在运行命令 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?
那么您想要安装在最新 Java 安装文件夹中的 keytool 吗?
您希望别名是您用于在 eclipse 中创建普通 apk 的别名的名称吗?
您希望密钥库是您在导出 Android 应用程序时使用的密钥库吗?
您希望 openssl 成为您刚刚安装的那个吗?
Yes to all of questions above. PATHcould be setup not to type full path for keytool and openssl.
对以上所有问题都是肯定的。PATH可以设置为不键入 keytool 和 openssl 的完整路径。