根据请求我得到这样的JSON:
{
"authentications": [
{
"type": "clientCertificate",
"secret": "...",
"pem": "-----BEGIN ENCRYPTED PRIVATE KEY-----
abc..
-----END ENCRYPTED PRIVATE KEY-----
-----BEGIN CERTIFICATE-----
abc...
-----END CERTIFICATE-----\n"
}
]
}
现在我必须创建一个证书并使用它来与服务器通信。有人可以帮我吗?
答案 0 :(得分:1)
看起来像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();
}