MD5: Difference in output of keytool.exe in Java 7 and above

主宰稳场 提交于 2020-01-03 05:38:08

问题


I have raised my concerns in the following thread:

how i can get MD5 hash in jdk.7.o?

and seen threads like:

Cannot use Java 7 installation if Java 8 is installed

and I have also studied:

https://docs.oracle.com/cd/E74665_01/MOSHP/settings.htm#CIHEFHEF

but no use.

Since I am using JRE/JDK version > 10, I am unable to obtain MD5 from any keystore of my choice using keytools. It is said that MD5 can be obtained from the keystore, if my JRE version is 7.

Also, I have tried and known that when this command is issued inside Android Studio or Eclipse for the Android's default keystore, that is developers keystore, it readily gives MD5 there. So I also had raised the question about how Android Studio or Eclipse is able to do that when my JRE version is > 10?

So I am trying to find the solution, other way round, for the same problem.

  1. In what way, I can still be able to use features of JRE/JDK v7, while v10 remained installed? In what way, I can be able to specify in java control panel in Window 7 (that is my OS), that I want to use Java 7.

  2. It is difficult for me to get "Support Identifier" information, for the oracle support, to get that version. So someone can guide me how to obtain that as well.

Please search for "Java SE 7, and Java SE 6 updates" in the site page:

https://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html

Please look for "Support Identifier" in the page that opens, after you click on the hyperlink : "My Oracle Support" in that paragraph, that follows.

[EDIT (for possible answer)]: Here is some code that uses key-store and finds out the Base64 of SHA value from keyStore:

 try {
        PackageInfo info = getPackageManager().getPackageInfo(
                "com.sample.app", 
                PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
    /*Note: may be instead of converting obtained bytes into Base64, 
I should convert it into hex string.*/
            }
    } catch (NameNotFoundException e) {

    } catch (NoSuchAlgorithmException e) {

    }

Please let me know if this suggests an answer. MD5 should be at least 32 bytes long.

Best Regards,

Your Follower.


回答1:


Surely the answer is given in the thread:

How to read SHA and MD5 fingerprint programmatically in Android ?

Here in this answer @NateZh has used code to get "MD5" instance of Digest straight forwardly instead of "SHA", together with converting byteArray[] to HEX String, as well as providing variations:

a. Getting MD5 from signature.

b. Getting MD5 from byteArray[]

Hints:

MessageDigest messageDigest = null;
StringBuffer md5StrBuff = new StringBuffer();
try {
messageDigest = MessageDigest.getInstance("MD5");
//... so on

Happy Coding and Exploring :-)

Best Regards



来源:https://stackoverflow.com/questions/52536801/md5-difference-in-output-of-keytool-exe-in-java-7-and-above

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