我完全不明白这个过程。我已经能够导航到Java SDK中包含keytool的文件夹。虽然我一直得到错误openssl不识别为内部或外部命令。问题是,即使我能让它工作,我该做什么,然后做什么?
当前回答
下载open ssl:
然后将openssl\bin添加到路径系统变量中:
我的电脑->属性->高级配置->高级->系统变量->系统变量下查找路径,并将此添加到其结尾: ; yourFullOpenSSLDir \ bin
现在在你的jdk\bin文件夹C:\Program Files\Java\ jdk1.8.0_40\bin上打开一个命令行(在windows上按住shift并右键单击->打开命令行此处),并使用:
keytool -exportcert -alias keystorealias -keystore C:\yourkeystore\folder\keystore.jks | openssl sha1 -binary | openssl base64
并复制它在给出密码后生成的长度为28的数字。
其他回答
自从API 26以来,你可以在KOTLIN中使用以下代码生成你的HASH key,而不需要任何Facebook SDK。
fun generateSSHKey(context: Context){
try {
val info = context.packageManager.getPackageInfo(context.packageName, PackageManager.GET_SIGNATURES)
for (signature in info.signatures) {
val md = MessageDigest.getInstance("SHA")
md.update(signature.toByteArray())
val hashKey = String(Base64.getEncoder().encode(md.digest()))
Log.i("AppLog", "key:$hashKey=")
}
} catch (e: Exception) {
Log.e("AppLog", "error:", e)
}
}
我遇到了完全相同的问题,我没有被要求提供密码,而且似乎我的密钥库文件路径错误。
事实上,如果keytool没有找到您设置的密钥存储库,它将创建一个密钥存储库,并提供错误的密钥,因为它没有使用正确的密钥。
一般的规则是,如果你没有被要求输入密码,那么你生成了错误的密钥。
这就是我如何获得我的:
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键。你所要做的就是复制它。
private fun generateKeyHash(): String? {try {
val info =packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES)
for (signature in info.signatures) {
val md: MessageDigest = MessageDigest.getInstance("SHA")
md.update(signature.toByteArray())
return String(Base64.encode(md.digest(), 0))
}
} catch (e: Exception) {
Log.e("exception", e.toString())
}
return "key hash not found"
}
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安装在其他地方。
推荐文章
- 如何在android中获得当前前景活动上下文?
- JavaFX应用程序图标
- Java:强/软/弱/幻影引用的区别
- 如何在Android中获取当前日期?
- 在序列化和反序列化期间JSON属性的不同名称
- 获取Android设备名称
- Gradle代理配置
- 在WebView中上传文件
- 加载HTML文件到WebView
- Android:为什么视图没有maxHeight ?
- 如何获得具有已知资源名称的资源id ?
- 在Android上将字符串转换为整数
- 为什么“System.out。”println“工作在Android?
- 在Java中什么时候使用可变参数?
- WebView显示err_cleartext_not_allowed尽管站点是HTTPS