• 获取keystore中的公钥模数及md5


    app备案时需要使用apk中的签名公钥,以及md5,但官方提供的方法是使用jadxGUI去打开apk获取:

    填写App特征信息_备案-阿里云帮助中心

     实际生产中apk都没有可能就要走备案流程。

    但其实公钥模数和md5不需要apk,只需要keystore就行了。

    这里自撸了一个jar来输出keystore的公钥模数与md5。

    下载链接:

    https://download.csdn.net/download/luozhi3527/88377524

    jar包使用很简单:

    java -jar ParseKeystore-1.0.jar keystorePath password alias

    回车即可得到keystore的模数与md5值:

    需要注意的是,keystore的生成环境与解析环境要一致,否则可能导致失败。比如kesytore使用的jdk17生成的,然后在1.8环境下执行这个jar包就可能报错。

    anyway,报错就用下面的源码自撸吧。

    源码:

    1. public class Main {
    2. private static final String CERTIFICATE_TYPE_NAME = "X.509";
    3. public static void main(String[] args) {
    4. String path, password, alias;
    5. if (args.length == 3) {
    6. path = args[0];
    7. password = args[1];
    8. alias = args[2];
    9. } else {
    10. System.out.println("error, must fill path, password, alias params");
    11. return;
    12. }
    13. System.out.println("path: " + path + ", password:" + password + ", alias:" + alias);
    14. try {
    15. FileInputStream is = new FileInputStream(path);
    16. KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
    17. char[] passwd = password.toCharArray();
    18. keystore.load(is, passwd);
    19. Certificate cert = keystore.getCertificate(alias);
    20. String type = cert.getType();
    21. RSAPublicKey pub = (RSAPublicKey) cert.getPublicKey();
    22. String modulus = pub.getModulus().toString(10);
    23. System.out.println("modulus: " + modulus);
    24. if (CERTIFICATE_TYPE_NAME.equals(type) && cert instanceof X509Certificate) {
    25. X509Certificate x509cert = (X509Certificate) cert;
    26. String md5 = getThumbPrint(x509cert, "MD5");
    27. System.out.println("md5: " + md5);
    28. }
    29. } catch (Exception e) {
    30. e.printStackTrace();
    31. }
    32. }
    33. public static String getThumbPrint(X509Certificate cert, String type)
    34. throws NoSuchAlgorithmException, CertificateEncodingException {
    35. MessageDigest md = MessageDigest.getInstance(type);
    36. byte[] der = cert.getEncoded();
    37. md.update(der);
    38. byte[] digest = md.digest();
    39. return hexify(digest);
    40. }
    41. public static String hexify(byte[] bytes) {
    42. char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
    43. StringBuilder buf = new StringBuilder(bytes.length * 3);
    44. for (byte aByte : bytes) {
    45. buf.append(hexDigits[(aByte & 0xf0) >> 4]);
    46. buf.append(hexDigits[aByte & 0x0f]);
    47. buf.append(' ');
    48. }
    49. return buf.toString();
    50. }
    51. }

  • 相关阅读:
    Lodash初识
    Cesium:OSGB倾斜摄影模型加载卡顿优化
    虹科动态 | 8月23日,虹科诚邀您参加上海电子设计创新大会(EDICON Across China 2022上海站)
    Python爬虫:某书平台的Authorization参数js逆向
    【React native】navigation 状态重置
    数据结构题型11-顺序队列
    详解MySQL C API 相关接口(大白话就是:MySQL的c语言怎么写)
    01 INFINI-GATEWAY简介
    android源码编译环境准备(1)
    Promise实现resolve/reject/then/all/race/finally/catch
  • 原文地址:https://blog.csdn.net/luozhi3527/article/details/133315993