/** * Creates an X.509 certificate from its ASN.1 encoded form. * * @param encoded PEM or DER encoded ASN.1 data. * * @return Certificate. * * @throws EncodingException on cert parsing errors. */ public static X509Certificate decodeCertificate(final byte[] encoded) throws EncodingException { return readCertificate(new ByteArrayInputStream(encoded)); }
/** {@inheritDoc} */ @Override public X509Certificate getObject() throws Exception { if (certificate == null) { if (resource == null) { throw new BeanCreationException("Certificate resource must be provided in order to use this factory."); } try (InputStream is = resource.getInputStream()) { certificate = CertUtil.readCertificate(is); } } return certificate; }
/** * Read certificate. * * @param resource the resource to read the cert from * @return the x 509 certificate */ public static X509Certificate readCertificate(final Resource resource) { try (InputStream in = resource.getInputStream()) { return CertUtil.readCertificate(in); } catch (final Exception e) { throw new RuntimeException("Error reading certificate " + resource, e); } }
/** * Read certificate. * * @param resource the resource to read the cert from * @return the x 509 certificate */ public static X509Certificate readCertificate(final InputStreamSource resource) { try (val in = resource.getInputStream()) { return CertUtil.readCertificate(in); } catch (final IOException e) { throw new IllegalArgumentException("Error reading certificate " + resource, e); } }
/** * Reads an X.509 certificate from ASN.1 encoded format in the file at the given location. * * @param path Path to file containing an DER or PEM encoded X.509 certificate. * * @return Certificate. * * @throws EncodingException on cert parsing errors. * @throws StreamException on IO errors. */ public static X509Certificate readCertificate(final String path) throws EncodingException, StreamException { return readCertificate(StreamUtil.makeStream(new File(path))); }
/** * Reads an X.509 certificate from ASN.1 encoded format from the given file. * * @param file File containing an DER or PEM encoded X.509 certificate. * * @return Certificate. * * @throws EncodingException on cert parsing errors. * @throws StreamException on IO errors. */ public static X509Certificate readCertificate(final File file) throws EncodingException, StreamException { return readCertificate(StreamUtil.makeStream(file)); }