Search in sources :

Example 1 with PemReader

use of com.android.org.bouncycastle.util.io.pem.PemReader in project android_frameworks_base by ParanoidAndroid.

the class Credentials method convertFromPem.

/**
     * Convert objects from PEM format, which is used for
     * CA_CERTIFICATE and USER_CERTIFICATE entries.
     */
public static List<X509Certificate> convertFromPem(byte[] bytes) throws IOException, CertificateException {
    ByteArrayInputStream bai = new ByteArrayInputStream(bytes);
    Reader reader = new InputStreamReader(bai, Charsets.US_ASCII);
    PemReader pr = new PemReader(reader);
    CertificateFactory cf = CertificateFactory.getInstance("X509");
    List<X509Certificate> result = new ArrayList<X509Certificate>();
    PemObject o;
    while ((o = pr.readPemObject()) != null) {
        if (o.getType().equals("CERTIFICATE")) {
            Certificate c = cf.generateCertificate(new ByteArrayInputStream(o.getContent()));
            result.add((X509Certificate) c);
        } else {
            throw new IllegalArgumentException("Unknown type " + o.getType());
        }
    }
    pr.close();
    return result;
}
Also used : PemReader(com.android.org.bouncycastle.util.io.pem.PemReader) PemObject(com.android.org.bouncycastle.util.io.pem.PemObject) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) Reader(java.io.Reader) PemReader(com.android.org.bouncycastle.util.io.pem.PemReader) InputStreamReader(java.io.InputStreamReader) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Example 2 with PemReader

use of com.android.org.bouncycastle.util.io.pem.PemReader in project platform_frameworks_base by android.

the class Credentials method convertFromPem.

/**
     * Convert objects from PEM format, which is used for
     * CA_CERTIFICATE and USER_CERTIFICATE entries.
     */
public static List<X509Certificate> convertFromPem(byte[] bytes) throws IOException, CertificateException {
    ByteArrayInputStream bai = new ByteArrayInputStream(bytes);
    Reader reader = new InputStreamReader(bai, StandardCharsets.US_ASCII);
    PemReader pr = new PemReader(reader);
    try {
        CertificateFactory cf = CertificateFactory.getInstance("X509");
        List<X509Certificate> result = new ArrayList<X509Certificate>();
        PemObject o;
        while ((o = pr.readPemObject()) != null) {
            if (o.getType().equals("CERTIFICATE")) {
                Certificate c = cf.generateCertificate(new ByteArrayInputStream(o.getContent()));
                result.add((X509Certificate) c);
            } else {
                throw new IllegalArgumentException("Unknown type " + o.getType());
            }
        }
        return result;
    } finally {
        pr.close();
    }
}
Also used : PemReader(com.android.org.bouncycastle.util.io.pem.PemReader) PemObject(com.android.org.bouncycastle.util.io.pem.PemObject) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) Reader(java.io.Reader) PemReader(com.android.org.bouncycastle.util.io.pem.PemReader) InputStreamReader(java.io.InputStreamReader) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Example 3 with PemReader

use of com.android.org.bouncycastle.util.io.pem.PemReader in project android_frameworks_base by ResurrectionRemix.

the class Credentials method convertFromPem.

/**
     * Convert objects from PEM format, which is used for
     * CA_CERTIFICATE and USER_CERTIFICATE entries.
     */
public static List<X509Certificate> convertFromPem(byte[] bytes) throws IOException, CertificateException {
    ByteArrayInputStream bai = new ByteArrayInputStream(bytes);
    Reader reader = new InputStreamReader(bai, StandardCharsets.US_ASCII);
    PemReader pr = new PemReader(reader);
    try {
        CertificateFactory cf = CertificateFactory.getInstance("X509");
        List<X509Certificate> result = new ArrayList<X509Certificate>();
        PemObject o;
        while ((o = pr.readPemObject()) != null) {
            if (o.getType().equals("CERTIFICATE")) {
                Certificate c = cf.generateCertificate(new ByteArrayInputStream(o.getContent()));
                result.add((X509Certificate) c);
            } else {
                throw new IllegalArgumentException("Unknown type " + o.getType());
            }
        }
        return result;
    } finally {
        pr.close();
    }
}
Also used : PemReader(com.android.org.bouncycastle.util.io.pem.PemReader) PemObject(com.android.org.bouncycastle.util.io.pem.PemObject) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) Reader(java.io.Reader) PemReader(com.android.org.bouncycastle.util.io.pem.PemReader) InputStreamReader(java.io.InputStreamReader) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Example 4 with PemReader

use of com.android.org.bouncycastle.util.io.pem.PemReader in project android_frameworks_base by AOSPA.

the class Credentials method convertFromPem.

/**
     * Convert objects from PEM format, which is used for
     * CA_CERTIFICATE and USER_CERTIFICATE entries.
     */
public static List<X509Certificate> convertFromPem(byte[] bytes) throws IOException, CertificateException {
    ByteArrayInputStream bai = new ByteArrayInputStream(bytes);
    Reader reader = new InputStreamReader(bai, StandardCharsets.US_ASCII);
    PemReader pr = new PemReader(reader);
    try {
        CertificateFactory cf = CertificateFactory.getInstance("X509");
        List<X509Certificate> result = new ArrayList<X509Certificate>();
        PemObject o;
        while ((o = pr.readPemObject()) != null) {
            if (o.getType().equals("CERTIFICATE")) {
                Certificate c = cf.generateCertificate(new ByteArrayInputStream(o.getContent()));
                result.add((X509Certificate) c);
            } else {
                throw new IllegalArgumentException("Unknown type " + o.getType());
            }
        }
        return result;
    } finally {
        pr.close();
    }
}
Also used : PemReader(com.android.org.bouncycastle.util.io.pem.PemReader) PemObject(com.android.org.bouncycastle.util.io.pem.PemObject) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) Reader(java.io.Reader) PemReader(com.android.org.bouncycastle.util.io.pem.PemReader) InputStreamReader(java.io.InputStreamReader) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Example 5 with PemReader

use of com.android.org.bouncycastle.util.io.pem.PemReader in project android_frameworks_base by DirtyUnicorns.

the class Credentials method convertFromPem.

/**
     * Convert objects from PEM format, which is used for
     * CA_CERTIFICATE and USER_CERTIFICATE entries.
     */
public static List<X509Certificate> convertFromPem(byte[] bytes) throws IOException, CertificateException {
    ByteArrayInputStream bai = new ByteArrayInputStream(bytes);
    Reader reader = new InputStreamReader(bai, StandardCharsets.US_ASCII);
    PemReader pr = new PemReader(reader);
    try {
        CertificateFactory cf = CertificateFactory.getInstance("X509");
        List<X509Certificate> result = new ArrayList<X509Certificate>();
        PemObject o;
        while ((o = pr.readPemObject()) != null) {
            if (o.getType().equals("CERTIFICATE")) {
                Certificate c = cf.generateCertificate(new ByteArrayInputStream(o.getContent()));
                result.add((X509Certificate) c);
            } else {
                throw new IllegalArgumentException("Unknown type " + o.getType());
            }
        }
        return result;
    } finally {
        pr.close();
    }
}
Also used : PemReader(com.android.org.bouncycastle.util.io.pem.PemReader) PemObject(com.android.org.bouncycastle.util.io.pem.PemObject) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) Reader(java.io.Reader) PemReader(com.android.org.bouncycastle.util.io.pem.PemReader) InputStreamReader(java.io.InputStreamReader) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Aggregations

PemObject (com.android.org.bouncycastle.util.io.pem.PemObject)6 PemReader (com.android.org.bouncycastle.util.io.pem.PemReader)6 ByteArrayInputStream (java.io.ByteArrayInputStream)6 InputStreamReader (java.io.InputStreamReader)6 Reader (java.io.Reader)6 Certificate (java.security.cert.Certificate)6 CertificateFactory (java.security.cert.CertificateFactory)6 X509Certificate (java.security.cert.X509Certificate)6 ArrayList (java.util.ArrayList)6