如题:csr证书文件包含了一把公钥,以及CA机构对这把公钥的签名,所以直接用文本方式打开CSR文件看到并不是真正的公钥,真正的公钥需要用一定方式才能获取到:
public static String convertPemToPKCS10CertificationRequest(String path) {
InputStream input = new FileInputStream(path);
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
PemReader pemReader = new PemReader(new InputStreamReader(input));
PEMParser pemParser = new PEMParser(pemReader);
PKCS10CertificationRequest csr = null;
StringWriter output = new StringWriter();
try {
csr = new PKCS10CertificationRequest(pemParser.readPemObject().getContent());
PemObject pkPemObject = new PemObject("PUBLIC KEY",
csr.getSubjectPublicKeyInfo().getEncoded());
PemWriter pemWriter = new PemWriter(output);
pemWriter.writeObject(pkPemObject);
pemWriter.close();
log.debug("PemParser returned: "+output.getBuffer());
} catch (IOException ex) {
log.error("IOException, convertPemToPublicKey", ex);
}
return output.getBuffer().toString();
}