如何使用我获得的自签名证书 JSON?

How to use a self-signed certificate which i get as JSON?

从请求中我得到一个 JSON 这样的:

    {
    "authentications": [
        {
            "type": "clientCertificate",
            "secret": "...",
            "pem": "-----BEGIN ENCRYPTED PRIVATE KEY-----
                    abc..
                    -----END ENCRYPTED PRIVATE KEY-----
                    -----BEGIN CERTIFICATE-----
                    abc...
                    -----END CERTIFICATE-----\n"
        }
    ]
}

现在我必须从中创建证书并使用它与服务器通信。有人可以帮我吗?

看起来像 PEM。您可以使用 bouncycastle.

阅读 PEM

更新:

以下是您如何使用证书链读取密钥对的示例:

        PEMReader in = new PEMReader(reader, dlg);
        Object obj = in.readObject();
        if (obj == null) {
            // Some PEM files have garbarge at the top
            for (int i = 0; i < 9 && obj == null; ++i) {
                obj = in.readObject();
            }
        }
        keys = null;
        if (obj instanceof KeyPair) {
            keys = (KeyPair)obj;
            obj = in.readObject();
        }
        List<X509Certificate> list = new ArrayList<X509Certificate>();
        while (obj != null) {
            if (obj instanceof X509Certificate) {
                list.add((X509Certificate)obj);
            }
            obj = in.readObject();
        }