FileReader fileReader = new FileReader("/path/to/cert.pem"); PEMReader pemReader = new PEMReader(fileReader); Object obj = pemReader.readObject(); pemReader.close(); // sloppy IO handling, be thorough in production code X509CertificateObject certObj = (X509CertificateObject) obj; System.out.println(certObj.getPublicKey());
private NamedGroup getPublicNamedGroup(Certificate cert) { if (cert.isEmpty()) { throw new IllegalArgumentException("Empty CertChain provided!"); } if (!(publicKey instanceof CustomEcPublicKey)) { return null; } try { X509CertificateObject obj = new X509CertificateObject(cert.getCertificateAt(0)); if (obj.getPublicKey() instanceof BCECGOST3410PublicKey) { return NamedGroup.GOST3410; } if (obj.getPublicKey() instanceof BCECGOST3410_2012PublicKey) { return NamedGroup.GOST3410_2012; } BCECPublicKey ecKey = (BCECPublicKey) obj.getPublicKey(); ECNamedCurveSpec spec = (ECNamedCurveSpec) ecKey.getParams(); return NamedGroup.fromJavaName(spec.getName()); } catch (Exception ex) { LOGGER.warn("Could not determine EC public key group", ex); return null; } }
if (obj.getPublicKey() instanceof BCECGOST3410PublicKey) { return NamedGroup.GOST3410; if (obj.getPublicKey() instanceof BCECGOST3410_2012PublicKey) { return NamedGroup.GOST3410_2012; BCECPublicKey ecKey = (BCECPublicKey) obj.getPublicKey(); ECNamedCurveSpec spec = (ECNamedCurveSpec) ecKey.getParams(); NamedGroup group = NamedGroup.fromJavaName(spec.getName());
public static PublicKey fetchServerPublicKey(Config config) { X509CertificateObject cert; try { Certificate fetchedServerCertificate = fetchServerCertificate(config); if (fetchedServerCertificate != null && fetchedServerCertificate.getLength() > 0) { cert = new X509CertificateObject(fetchedServerCertificate.getCertificateAt(0)); return cert.getPublicKey(); } } catch (CertificateParsingException ex) { throw new WorkflowExecutionException("Could not get public key from server certificate", ex); } return null; }
buf.append(" Final Date: ").append(this.getNotAfter()).append(nl); buf.append(" SubjectDN: ").append(this.getSubjectDN()).append(nl); buf.append(" Public Key: ").append(this.getPublicKey()).append(nl); buf.append(" Signature Algorithm: ").append(this.getSigAlgName()).append(nl);