我有加载客户端私钥的代码
// load client private key
PEMParser pemParser = new PEMParser(new FileReader(keyFile));
Object object = pemParser.readObject();
PEMDecryptorProvider decProv = new JcePEMDecryptorProviderBuilder().build(password.toCharArray());
JcaPEMKeyConverter converter = new JcaPEMKeyConverter().setProvider("BC");
KeyPair key;
if (object instanceof PEMEncryptedKeyPair) {
System.out.println("Encrypted key - we will use provided password");
key = converter.getKeyPair(((PEMEncryptedKeyPair) object)
.decryptKeyPair(decProv));
} else {
System.out.println("Unencrypted key - no password needed "+object.getClass().getName());
key = converter.getKeyPair((PEMKeyPair) object);
}
pemParser.close();
在某些情况下,
pemParser.readObject()
返回类PEMKeyPair
的对象,这很好。但如果我在下面定义了客户端密钥,则返回 pemParser.readObject()
的实例。为什么我会得到 PrivateKeyInfo
以及在这种情况下如何处理? 客户端密钥:
PrivateKeyInfo
UPD
说实话,我的安全性并不强,当我从 pemParser.readObject() 获取
-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC4weh0zOpMwqZc
y3oExJQ84Vhyrf/6IdGmUpHaexyrhbbuZD8SThb1O/pp/gs7ZOgqXLQx5jYEwncO
7VVlDJg8inKDaeDZn/EHmTqs4AVYAxvqXU4C9J3QKw4+zf/WRbvd1FWMvD/Lurqn
3/UF0iIjiyu/sZojyQ1VnWAHGtnuYIGEKij12fQt+AMhcuYKPExaCdB7rQocEnxw
/AxKRTHmRPHu9f1ny78ALCBMp8/3UdclHCL2Hszcpj+mfRwoRMVDER0LA3edUnGj
kkhbxGckSvGatmknNRzsf4XhSAfxb1kXEtX1ZQd7/ZPIxE1JZSbljgOIi5X1CLpc
gGD4vYaDAgMBAAECggEBALfa9vksZchnN2hGcDFIcf+3e+37Kyz99IQfzNbvBlPF
p4nJpl4P6Za2zfYmAYVkYAiv4f16Cq1n21S2ZvE8vE4as+QEO+Y03IVkPViFQawY
w/HQUe5tAJKEFhP3qSzQjigswclgF9gkBNVD76+QMbrPJo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6
-----END PRIVATE KEY-----
时,我不知道如何构造
KeyStore
对象。完整程序代码:
PrivateKeyInfo
如果您发现了什么,请分享。