Keytool生成32个字符的长密钥哈希,而不是28个 [英] Keytool generates 32 character long key hash instead of 28
问题描述
我正在使用以下命令为Android版Facebook应用程序控制台生成密钥哈希
I am using the following command to generate key hash for Facebook app console for Android
.\keytool.exe -exportcert -alias app_android -keystore release.keystore | openssl sha1 -binary | openssl base64
根据帮助页面以及开发人员控制台,密钥哈希应为28个字符长,但是keytool会生成32个字符长的密钥.
As per the help page and also the developers console, the key hash should be 28 characters long, however the keytool is generating 32 characters long key.
Java版本:jdk1.8.0_31 操作系统:Windows 7
Java version : jdk1.8.0_31 OS : Windows 7
为Android生成.
Generating for android.
编辑
根据@ Shreyash-mashru的建议,我使用以下代码获取了密钥哈希
As per suggestion from @Shreyash-mashru, I used the following code to get the keyhash
try {
PackageInfo info = getPackageManager().getPackageInfo(
"my.package.name",
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.e("KeyHash:", "++++++++++++++++++++++++++++++++++++++" + Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (PackageManager.NameNotFoundException e) {
Log.e("KeyHash:", "++++++++++++++++++++++++++++++++++++++" + e.toString());
} catch (NoSuchAlgorithmException e) {
Log.e("KeyHash:", "++++++++++++++++++++++++++++++++++++++" + e.toString());
}
但是,如果有人仍然可以帮助我理解为什么命令行工具会生成32个字符长的键哈希而不是28个字符……
However if someone can still help me out understand why the command line tool is generating 32 char long key hash instead of 28...
推荐答案
也解决了这个问题,对我来说,我使用的是Windows powershell,并且它一直生成32个字符的密钥.当我切换到普通的旧cmd时,它按预期工作.
Came across this problem too, for me I was using windows powershell and it kept generating a 32 character key. When I switch to plain old cmd it worked as expected.
这篇关于Keytool生成32个字符的长密钥哈希,而不是28个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!