https代理服务器(五)换电脑

brew install mkcert

mkcert -CAROOT

没有

 

2

mkcert -install

mkcert -CAROOT

有了

 

3

启动MyFiddler,手机连接,失败

 

拷贝原key和证书至root目录

再次mkcert -install

 

5 好了

 

6 公钥摘要

public class PemReader {
    public static X509Certificate readCertificateFromPem(String filePath) throws Exception {
        try (InputStream is = new FileInputStream(filePath)) {
            CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
            X509Certificate certificate = (X509Certificate) certificateFactory.generateCertificate(is);
            return certificate;
        }
    }

    public static void main(String[] args) {
        try {
            X509Certificate cert = readCertificateFromPem("/Users/Zhuanz1/Library/Application Support/mkcert/rootCA.pem");
            System.out.println("Certificate Subject: " + cert.getSubjectX500Principal());
            PublicKey publicKey = cert.getPublicKey();
            byte []k = publicKey.getEncoded();
            System.out.println(encrypt(k));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static String encrypt(byte[] input) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(input);
            byte[] digest = md.digest();
            StringBuilder sb = new StringBuilder();
            for (byte b : digest) {
                sb.append(String.format("%02x", b & 0xff));
            }
            return sb.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

 

Certificate Subject: CN=mkcert mac@macdeMacBook.local, OU=mac@macdeMacBook.local, O=mkcert development CA
Disconnected from the target VM, address: '127.0.0.1:64269', transport: 'socket'
942fb8cd5be910509faf8a39dd189240

 

7 在旧电脑运行6的代码同样结果

posted on 2025-10-19 22:13  silyvin  阅读(2)  评论(0)    收藏  举报