List of usage examples for java.security.cert X509Certificate getEncoded
public abstract byte[] getEncoded() throws CertificateEncodingException;
From source file:org.globus.security.util.CertificateIOUtil.java
/** * Writes certificate to the specified output stream in PEM format. *//* ww w. j a va 2s . com*/ public static void writeCertificate(OutputStream out, X509Certificate cert) throws IOException, CertificateEncodingException { PEMUtil.writeBase64(out, "-----BEGIN CERTIFICATE-----", base64.encode(cert.getEncoded()), "-----END CERTIFICATE-----"); }
From source file:org.globus.gsi.util.CertificateIOUtil.java
/** * Writes certificate to the specified output stream in PEM format. *//* www. java2s.com*/ public static void writeCertificate(OutputStream out, X509Certificate cert) throws IOException, CertificateEncodingException { PEMUtil.writeBase64(out, "-----BEGIN CERTIFICATE-----", Base64.encode(cert.getEncoded()), "-----END CERTIFICATE-----"); }
From source file:org.globus.security.util.CertificateIOUtil.java
public static void writeCertificate(X509Certificate cert, File path) throws CertificateEncodingException, IOException { String pubKeyPEM = certToPEMString(base64.encodeToString(cert.getEncoded())); FileWriter pubFile = null;/*from w w w .j ava 2 s. c o m*/ try { pubFile = new FileWriter(path); pubFile.write(pubKeyPEM); } finally { if (pubFile != null) { pubFile.close(); } } }
From source file:be.fedict.eidviewer.lib.X509Utilities.java
public static String X509CertToBase64String(X509Certificate certificate) { if (certificate == null) return null; try {//w w w. j a va 2 s . c o m return eidBase64Encode(certificate.getEncoded()); } catch (CertificateEncodingException e) { return null; } }
From source file:org.tranche.server.logs.LogUtil.java
/** * Generate a MD5 certificate.//w w w. jav a 2s . com * @param cert * @return * @throws java.lang.Exception */ public static byte[] createCertificateMD5(X509Certificate cert) throws Exception { return SecurityUtil.hash(cert.getEncoded(), "md5"); }
From source file:org.sinekartads.utils.X509Utils.java
public static String rawX509CertificateToHex(X509Certificate certificate) throws CertificateEncodingException { // Return the hex string relative to the given X509Certificate String hex = null;/*from w ww . j av a 2 s.c o m*/ if (certificate != null) { hex = HexUtils.encodeHex(certificate.getEncoded()); } return hex; }
From source file:org.wso2.carbon.apimgt.rest.api.publisher.utils.CertificateRestApiUtils.java
/** * To get the decoded certificate input stream. * * @param certificate Relevant encoded certificate * @return Input stream of the certificate. * @throws APIManagementException API Management Exception. *//*from www .j a v a 2 s .c o m*/ public static ByteArrayInputStream getDecodedCertificate(String certificate) throws APIManagementException { byte[] cert = (Base64.decodeBase64(certificate.getBytes(StandardCharsets.UTF_8))); ByteArrayInputStream serverCert = new ByteArrayInputStream(cert); try { CertificateFactory cf = CertificateFactory.getInstance("X.509"); if (serverCert.available() > 0) { Certificate generatedCertificate = cf.generateCertificate(serverCert); X509Certificate x509Certificate = (X509Certificate) generatedCertificate; return new ByteArrayInputStream(x509Certificate.getEncoded()); } } catch (CertificateException e) { throw new APIManagementException("Error while decoding the certificate", e); } return null; }
From source file:ee.ria.xroad.confproxy.ConfProxyProperties.java
/** * Quietly get the raw bytes of a certificate. * @param cert the certificate/*from ww w . j av a 2 s. c o m*/ * @return raw bytes for the provided certificate */ @SneakyThrows private static byte[] certBytes(final X509Certificate cert) { return cert.getEncoded(); }
From source file:at.gv.egiz.bku.spring.PKITrustManager.java
private static iaik.x509.X509Certificate[] convertCerts(X509Certificate[] certs) throws CertificateException { iaik.x509.X509Certificate[] retVal = new iaik.x509.X509Certificate[certs.length]; int i = 0;/*from w w w . j a v a2s . c o m*/ for (X509Certificate cert : certs) { if (cert instanceof iaik.x509.X509Certificate) { retVal[i++] = (iaik.x509.X509Certificate) cert; } else { retVal[i++] = new iaik.x509.X509Certificate(cert.getEncoded()); } } return retVal; }
From source file:org.glite.slcs.httpclient.ssl.ExtendedX509TrustManager.java
static private String getCertificateFingerprint(X509Certificate certificate, String algorithm) { byte[] digest = null; try {/*from w ww.ja v a 2 s .c o m*/ byte[] certificateBytes = certificate.getEncoded(); MessageDigest md = MessageDigest.getInstance(algorithm); md.update(certificateBytes); digest = md.digest(); } catch (CertificateEncodingException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return new String(algorithm + ": " + byteArrayToHex(digest)); }