我完全不明白这个过程。我已经能够导航到Java SDK中包含keytool的文件夹。虽然我一直得到错误openssl不识别为内部或外部命令。问题是,即使我能让它工作,我该做什么,然后做什么?
当前回答
我遇到了完全相同的问题,我没有被要求提供密码,而且似乎我的密钥库文件路径错误。
事实上,如果keytool没有找到您设置的密钥存储库,它将创建一个密钥存储库,并提供错误的密钥,因为它没有使用正确的密钥。
一般的规则是,如果你没有被要求输入密码,那么你生成了错误的密钥。
其他回答
以下是你需要做的
从代码下载openSSl 提取它。在C:/目录下创建一个名为OpenSSL的文件夹,并将解压后的代码复制到这里。
检测调试。Keystore文件路径。如果你没有找到,那么在C:/中进行搜索,并在下一步中使用命令中的Path。
检测您的keytool.exe路径,并进入dir/ in命令提示符,并在一行中运行此命令
$ keytool -exportcert -alias androiddebugkey -keystore "C:\Documents and Settings\Administrator.android\debug.keystore" | "C:\OpenSSL\bin\openssl" sha1 -binary |"C:\OpenSSL\bin\openssl" base64
它会要求输入密码,输入android 这是所有。你会得到一个key-hash
https://developers.facebook.com/docs/android/getting-started/
4.19.0 - 2017年1月25日
Facebook SDK
修改
Facebook SDK现在在应用程序启动时自动初始化。在大多数情况下,不再需要手动调用FacebookSDK.sdkInitialize()。有关详细信息,请参见升级指南。
为调试
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 (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
this will help newbees also. just adding more details to @coder_For_Life22's answer. if this answer helps you don't forget to upvote. it motivates us. for this you must already know the path of the app's keystore file and password for this example consider the key is stored at "c:\keystorekey\new.jks" 1. open this page https://code.google.com/archive/p/openssl-for-windows/downloads 2. download 32 or 64 bit zip file as per your windows OS. 3. extract the downloaded file where ever you want and remember the path. 4. for this example we consider that you have extracted the folder in download folder. so the file address will be "C:\Users\0\Downloads\openssl-0.9.8e_X64\bin\openssl.exe"; 5. now on keyboard press windows+r button. 6. this will open run box. 7. type cmd and press Ctrl+Shift+Enter. 8. this will open command prompt as administrator. 9. here navigate to java's bin folder: if you use jre provided by Android Studio you will find the path as follows: a. open android studio. b. file->project structure c. in the left pane, click 'SDK location' d. in the right pane, below 'JDK location' is your jre path. e. add "\bin" at the end of this path as the file "keytool.exe", we need, is inside this folder. for this example i consider, you have installed java separately and following is the path "C:\Program Files\Java\jre-10.0.2\bin" if you have installed 32bit java it will be in "C:\Program Files (x86)\Java\jre-10.0.2\bin" 10. now with above paths execute command as following:
keytool -exportcert -alias androiddebugkey -keystore "c:\keystorekey\new.jks" | "C:\Users\0\Downloads\openssl-0.9.8e_X64\bin\openssl.exe" sha1 -binary |"C:\Users\0\Downloads\openssl-0.9.8e_X64\bin\openssl.exe" base64
您将被要求输入密码,请输入您在创建密钥存储库密钥时所提供的密码。 ! ! 这将给你钥匙
错误: 如果你得到: --- 'keytool'不能被识别为内部或外部命令 --- 这意味着Java安装在其他地方。
这里是完整的细节(适用于Windows)
1. 根据您的32位或64位系统下载第三或第四版OpenSSl(使用e会更好)。
2. 解压到C目录下下载的zip文件
3.打开解压的文件夹到bin并复制路径,它应该是C:\openssl-0.9.8 k_x64 \bin\openssl(在结束时添加\openssl)
4. (获取Jdk bin文件夹的路径,如果你知道怎么做,忽略这个)。
打开android studio ~file~Project Structure(ctrl+alt+shift+s),在左侧面板中选择SDK location,复制JDK位置并添加/bin
因此,最终的JDK位置将类似于C:\Program Files\Android\Android Studio\jre\bin
我们使用这种方法来获取Jdk的位置,因为你可能像我一样使用嵌入式Jdk
现在你有了OpenSSl的位置和JDK的位置
5. 现在我们需要调试密钥库的位置,为打开C~>Users~>YourUserName~>。Android应该有一个文件名调试。Keystore,复制路径位置,应该是这样的
C:\Users\Redman\.android\ debug.keystore
6. 现在打开命令提示符并键入命令
cd YourJDKLocationFromStep4
对我来说
cd "C:\Program Files\Android\Android Studio\jre\bin"
7. 现在构造以下命令
keytool -exportcert -alias androiddebugkey -keystore YOURKEYSTORELOCATION | YOUROPENSSLLOCATION sha1 -binary | YOUROPENSSLLOCATION base64
在我的例子中,命令如下所示
keytool -exportcert -alias androiddebugkey -keystore "C:\Users\Redman\.android\debug.keystore" | "C:\openssl-0.9.8k_X64\bin\openssl" sha1 -binary | "C:\openssl-0.9.8k_X64\bin\openssl" base64
现在在命令提示符中输入这个命令,如果你做对了,你会被要求输入密码(密码是android)
Enter keystore password: android
就是这样,你会得到Key Hash,只是复制它并使用它
对于Signed KeyHash,构造以下命令
keytool -exportcert -alias YOUR_ALIAS_FOR_JKS -keystore YOUR_JKS_LOCATION | YOUROPENSSLLOCATION sha1 -binary | YOUROPENSSLLOCATION base64
输入您的密钥库密码,如果您输入错误的密码,它将给出错误的KeyHash
请注意
如果出于某种原因,如果它在某些路径上给出错误,那么将该路径用双引号括起来。此外,Windows power shell对我来说工作不太好,我使用git bash(或使用命令提示符)。
例子
keytool -exportcert -alias androiddebugkey -keystore "C:\Users\Redman\.android\debug.keystore" | "C:\openssl-0.9.8k_X64\bin\openssl" sha1 -binary | "C:\openssl-0.9.8k_X64\bin\openssl" base64
这就是我如何获得我的:
private class SessionStatusCallback implements Session.StatusCallback {
@Override
public void call(Session session, SessionState state, Exception exception) {
if (exception != null) {
new AlertDialog.Builder(FriendActivity.this)
.setTitle(R.string.login_failed_dialog_title)
.setMessage(exception.getMessage())
.setPositiveButton(R.string.ok_button, null)
.show();
}
因此,当您试图在没有密钥的情况下输入时,将会出现异常。Facebook在这个例外中加入了RIGHT键。你所要做的就是复制它。
推荐文章
- 如何解决INSTALL_FAILED_DEXOPT错误?
- 有没有办法自动安装Android SDK ?
- 如何检查一个视图在Android中是否可见?
- 一对多、多对一、多对多的区别?
- Android是否保留。apk文件?如果有,在哪里?
- 从枚举中选择一个随机值?
- 如何从URL获取参数与JSP
- 如何在Eclipse中生成Javadoc注释?
- 找到java类从哪里加载
- 从集合中随机选取一个元素
- 为什么x == (x = y)和(x = y) == x不一样?
- 什么Java 8流。收集等价物可在标准Kotlin库?
- 在Android 5棒棒糖中,通知栏图标变成白色
- 从URI获取真实路径,Android奇巧新的存储访问框架
- 等待未来的名单