Keytool generates 32 character long key hash instead of 28

旧时模样 提交于 2019-12-03 03:41:51

问题


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

As told at Facebook developers SDK help

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 version : jdk1.8.0_31 OS : Windows 7

Generating for android.

EDIT

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());
    }

However if someone can still help me out understand why the command line tool is generating 32 char long key hash instead of 28...


回答1:


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.




回答2:


The generated hash is 32 characters because there is a carriage return and a newline added to the end. To fix this you can either:

Delete the last 5 characters of the hash, and add an "=" to the end. For example: "1234567890abcdefghijklmnopqrstuv" (32 chars) --> "1234567890abcdefghijklmnopq=" (28 chars)

Or:

pop open a javascript console, and use:

btoa(atob("your hash string").slice(0, -2))

Where "your hash string" is your 32 character hash.




回答3:


I was having the same problem. It had something to do with using my existing version of openSSL (64 bit). I downloaded the 32 bit version from here and installed it to c:\openSSL. The command then points to this version of SSL and I got my 28 character hash.

keytool -exportcert -alias androiddebugkey -keystore "C:\Users\USERNAME.android\debug.keystore" | "C:\OpenSSL\bin\openssl" sha1 -binary |"C:\OpenSSL\bin\openssl" base64




回答4:


TRY THE COMMAND IN COMMAND PROMPT !

it will ask you for password then you will get the hash key

Trying the same command on powershell doesn't provide correct hash key.




回答5:


.\keytool.exe -exportcert -alias app_android -keystore release.keystore | openssl sha1 -binary | openssl base64

this is working fine for me. try it again.



来源:https://stackoverflow.com/questions/33340242/keytool-generates-32-character-long-key-hash-instead-of-28

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!