代码如下,仅供参考
private Key getPrivateKeyFormPfx(String pfxFilePath, String strPassword) {
try (FileInputStream fis = new FileInputStream(pfxFilePath)) {
char[] nPassword = strPassword.toCharArray();
KeyStore ks = KeyStore.getInstance("PKCS12");
ks.load(fis, nPassword);
fis.close();
Enumeration<String> enumerations = ks.aliases();
String keyPFXFile = null;
if (enumerations.hasMoreElements()) {
keyPFXFile = enumerations.nextElement();
}
return ks.getKey(keyPFXFile, nPassword);
} catch (Exception e) {
logger.error("读取pfx文件异常!", e);
}
return null;
}