Is there any way to get key hash from signed APK?

做~自己de王妃 提交于 2019-11-26 12:55:59

问题


Is there any way to get key hash from signed APK? We have a signed Android apk file, and we want to find out key hash of this APK, for Facebook SDK. Can we do that by something like jarsigner?
Any suggestions?


回答1:


For windows users getting the key from openssl, may be tricky some times.. I always use this to find the right signature.. Just paste this code in your onCreate() and run.

 // Add code to print out the key hash
  try {
  PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
  for (Signature signature : info.signatures) {
  MessageDigest md = MessageDigest.getInstance("SHA");
  md.update(signature.toByteArray());
  Log.e("MY KEY HASH:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
      }
  } catch (NameNotFoundException e) {

  } catch (NoSuchAlgorithmException e) {

  }

Update:

Using Android studio(2.1.2):

  1. Open your project on studio and click on the gradle icon.
  2. Choose your app -> Tasks -> android -> SigningReport

This will run a gradle task that will print the debug and release certificate with md5 and sha1 keys




回答2:


On linux, I used this command to get the key hash from an apk:

 keytool -list -printcert -jarfile [path_to_your_apk] | grep -Po "(?<=SHA1:) .*" |  xxd -r -p | openssl base64

For Mac Users (OS X) as there is no grep -P support

keytool -list -printcert -jarfile ~/Downloads/YOURAPKFILE.apk | grep "SHA1: " | cut -d " " -f 3 | xxd -r -p | openssl base64




回答3:


You can download openssa from here

  1. To generate signature you need openssl installed on your pc. If you don’t have one download openssl from here
  2. In C: , Create openssl folder
  3. Extract the contents of downloaded openssl zip file into openssl folder in C:drive
  4. Open Command prompt
  5. Move to bin of openssl i.e C:\openssl\bin in command prompt
  6. Run the following command to generate your keyhash. While generating hashkey it should ask you password.

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

NOTE: In the above code, note that you need to give your path to user(i.e in my case it is C:\Users\Anhsirk, you just need to change this for your user account.

Give password as android. If it don’t ask for password your keystore path is incorrect.




回答4:


When I built my Facebook app. I used my Android keystore. There is a hashing function for that. Commonly used in the Google API's.(See there for instructions). If you own the app and signed it; this should be no issue otherwise..your basically screwed.There is no way.



来源:https://stackoverflow.com/questions/17423870/is-there-any-way-to-get-key-hash-from-signed-apk

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