我完全不明白这个过程。我已经能够导航到Java SDK中包含keytool的文件夹。虽然我一直得到错误openssl不识别为内部或外部命令。问题是,即使我能让它工作,我该做什么,然后做什么?
当前回答
Linux和Mac
开放式终端:
用于调试构建
keytool -exportcert -alias androiddebugkey -keystore debug.keystore | openssl sha1 -binary | openssl base64
你会发现调试。中的密钥存储库。android”文件夹。复制并粘贴到桌面上,然后运行上面的命令。
发布版本
keytool -exportcert -alias <aliasName> -keystore <keystoreFilePath> | openssl sha1 -binary | openssl base64
注意:确保在这两种情况下它都要求输入密码。如果它不要求输入密码,则意味着命令中有错误。调试密码。密钥存储库是“android”,为了发布,您必须输入您在创建密钥存储库时设置的密码。
其他回答
简单的方法
通过使用这个网站,您可以通过将SHA1密钥转换为Facebook的哈希密钥来获得哈希密钥。
请试试这个:
public static void printHashKey(Context pContext) {
try {
PackageInfo info = pContext.getPackageManager().getPackageInfo(pContext.getPackageName(), PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
String hashKey = new String(Base64.encode(md.digest(), 0));
Log.i(TAG, "printHashKey() Hash Key: " + hashKey);
}
} catch (NoSuchAlgorithmException e) {
Log.e(TAG, "printHashKey()", e);
} catch (Exception e) {
Log.e(TAG, "printHashKey()", e);
}
}
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安装在其他地方。
以下是你需要做的
从代码下载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
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"
}
推荐文章
- 什么是“android. r.b ayout.simple_list_item_1”?
- 将字符串转换为Uri
- 在Android中创建临时文件
- INSTALL_PARSE_FAILED_NO_CERTIFICATES错误是什么?
- 在Android中定义RelativeLayout视图的Z顺序
- jUnit中的字符串上的AssertContains
- 将JSON转换为映射
- Android Studio 3.0口味维度问题
- 在Java8中使用lambda仅在不为空时筛选值
- Java反射中的getFields和getDeclaredFields有什么区别
- 这个谷歌播放APK发布错误消息是什么意思?
- 如何检查一个文件夹是否存在?
- 如何创建在移动设备上呼叫电话号码的超链接?
- 错误:无法在intelliJ IDE中找到或加载主类
- 如何创建Android Facebook密钥哈希?