Java 8 CertificateFactory - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 CertificateFactory class.

This code example shows how to use the following methods:generateCertificate
                this.certGen.generateX509Certificate(this.caPrivate);
 
        final InputStream in = new ByteArrayInputStream(x509.getEncoded());
 
        final X509Certificate x509Cert =
                (X509Certificate) this.factory.generateCertificate(in);
 
        final X500Principal subjectDN = x509Cert.getSubjectX500Principal();
 
        final String DN = subjectDN.getName(X500Principal.RFC2253);
        final String globusDN = CertUtil.toGlobusID(DN, false);
 
        final String msg = "Created new certificate with DN (RFC2253) = '" +
                     DN + "' and Globus style DN = '" + globusDN + "'";
 
 
        return x509Cert;
    } 
 
    public X509CRL generateCRL()
5
CodeRank
This code example shows how to use the following methods:generateCertificate
                this.certGen.generateX509Certificate(this.caPrivate);
 
        InputStream in = new ByteArrayInputStream(x509.getEncoded());
 
        X509Certificate x509Cert =
                (X509Certificate) this.factory.generateCertificate(in);
 
        X500Principal subjectDN = x509Cert.getSubjectX500Principal();
 
        String DN = subjectDN.getName(X500Principal.RFC2253);
        String globusDN = CertUtil.toGlobusID(DN, false);
 
        String msg = "Created new certificate with DN (RFC2253) = '" +
                     DN + "' and Globus style DN = '" + globusDN + "'";
 
        logger.trace(msg);
 
        return x509Cert;
    } 
 
5
CodeRank
This code example shows how to use the following methods:generateCertificate
        test_generateCertificate(CertificateFactory.getInstance("X509", "BC"));
        test_generateCertificate(CertificateFactory.getInstance("X509", "DRLCertFactory"));
    } 
    private void test_generateCertificate(CertificateFactory cf) throws Exception {
        byte[] valid = VALID_CERTIFICATE_PEM.getBytes();
        Certificate c = cf.generateCertificate(new ByteArrayInputStream(valid));
        assertNotNull(c);
 
        try { 
            byte[] invalid = INVALID_CERTIFICATE_PEM.getBytes();
            cf.generateCertificate(new ByteArrayInputStream(invalid));
            fail();
        } catch (CertificateException expected) {
        } 
    } 
 
} 
5
CodeRank
This code example shows how to use the following methods:generateCertificate
    private static X509Certificate extractCertificate(JAXBElement<?> x509Item) throws CertificateException {
        @SuppressWarnings("unchecked") 
        JAXBElement<byte[]> byteElement = (JAXBElement<byte[]>) x509Item;
        byte[] bytes = byteElement.getValue();
        InputStream stream = new ByteArrayInputStream(bytes);
        Certificate certificate = X509_FACTORY.generateCertificate(stream);
        if (certificate instanceof X509Certificate) {
            return (X509Certificate) certificate;
        } else { 
            throw new CertificateException("Unsupported certificate type encountered: "
                    + certificate.getClass().getName());
        } 
    } 
 
    public static UnverifiedKeyBindingType getUnverifiedKeyBinding(X509Certificate cert)
        throws CertificateEncodingException {
        UnverifiedKeyBindingType unverifiedKeyBinding = new UnverifiedKeyBindingType();
        unverifiedKeyBinding.setKeyInfo(getKeyInfo(cert));
        return unverifiedKeyBinding;
    } 
4
CodeRank
This code example shows how to use the following methods:generateCertificate
		} 
 
		X509Certificate cert = null;
 
		try { 
			cert = (X509Certificate) certFactory.generateCertificate(new ByteArrayInputStream(encodedCert));
		} catch (Exception e) { 
			Log.w(TAG, "Failed while decoding certificate for identity No. " + index, e);
		} 
		return cert;
	} 
	 
	@Override 
	public PrivateKey getPrivateKey(int index) {
		 
		String keyKey = Keywords.key(index);
 
		byte[] encodedKey = secureStorage.getWithStringKey(keyKey);
		if (encodedKey == null) {
			Log.w(TAG, "Could not get private key for identity No. " + index);
4
CodeRank
This code example shows how to use the following methods:generateCertificate
This code example shows how to use the following methods:generateCertificate
    private X509Certificate loadCACertificate(String path) {
        InputStream inStream = null;
        try { 
            inStream = new FileInputStream(path);
            X509Certificate cert = (X509Certificate) this.certFactory
                .generateCertificate(inStream);
            inStream.close();
            return cert;
        } 
        catch (Exception e) {
            throw new RuntimeException(e);
        } 
        finally { 
            try { 
                if (inStream != null) {
                    inStream.close();
                } 
            } 
            catch (IOException e) {
                // ignore. there's nothing we can do. 
4
CodeRank
This code example shows how to use the following methods:generateCertificate
            return null; 
        } 
        InputStream is = null;
        try { 
            is = new BufferedInputStream(new FileInputStream(file));
            return (X509Certificate) CERT_FACTORY.generateCertificate(is);
        } catch (IOException e) {
            return null; 
        } catch (CertificateException e) {
            // reading a cert while its being installed can lead to this. 
            // just pretend like its not available yet. 
            return null; 
        } finally { 
            IoUtils.closeQuietly(is);
        } 
    } 
 
    private void writeCertificate(File file, X509Certificate cert)
            throws IOException, CertificateException { 
        File dir = file.getParentFile();
4
CodeRank
This code example shows how to use the following methods:generateCertificate
     * Convert a DER encoded certificate to an X509Certificate. 
     */ 
    public static X509Certificate createCertificateFromBytes(byte[] derBytes) throws
            CertificateException, KeyStoreException, NoSuchAlgorithmException {
        ensureInitialized(); 
        return (X509Certificate) sCertificateFactory.generateCertificate(
                new ByteArrayInputStream(derBytes));
    } 
 
    public static void addTestRootCertificate(byte[] rootCertBytes) throws CertificateException,
            KeyStoreException, NoSuchAlgorithmException {
        ensureInitialized(); 
        X509Certificate rootCert = createCertificateFromBytes(rootCertBytes);
        synchronized (sLock) { 
            sTestKeyStore.setCertificateEntry( 
                    "root_cert_" + Integer.toString(sTestKeyStore.size()), rootCert); 
            reloadTestTrustManager(); 
        } 
    } 
 
3
CodeRank
This code example shows how to use the following methods:generateCertificate
        } 
        if (data == null) {
            return null; 
        } 
        try { 
            return (X509Certificate) certificateFactory.generateCertificate(new ByteArrayInputStream(data));
        } catch (CertificateException e) {
            throw new RuntimeException("Error deserializing certificate: " + e.getMessage(), e);
        } 
    } 
 
    @Override 
    public void saveCertificate(X509Certificate cert, UseKeyWithType key) {
        Applications application = Applications.fromUri(key.getApplication());
        String dn = null;
        Map<String, String> attrs = new HashMap<String, String>();
        if (application == Applications.PKIX) {
            dn = key.getIdentifier() + "," + rootDN;
        } else if (application == Applications.SERVICE_NAME) {
            dn = getDnForIdentifier(key.getIdentifier());
4
CodeRank

Related Java 8 CertificateFactory Questions & Answers:

See Code Examples for Java 8 CertificateFactory Methods: