Java Code Examples for

Following code examples demonstrate how to use android. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use various code implementation of this class.

    private Collection<X509CertificatePair> getCertPairs(
        LDAPRequest request, String id) throws CertStoreException {

        byte[][] encodedCertPair;
        try {
            encodedCertPair = request.getValues(id);
        } catch (NamingException namingEx) {
            throw new CertStoreException(namingEx);

        int n = encodedCertPair.length;
        if (n == 0) {
            return Collections.emptySet();

        List<X509CertificatePair> certPairs = new ArrayList<>(n);
        for (int i = 0; i < n; i++) {
            try {
                X509CertificatePair certPair =
            } catch (CertificateException e) {
                if (debug != null) {
                        "LDAPCertStore.getCertPairs() encountered exception "
                        + "while parsing cert, skipping the bad data: ");
                    HexDumpEncoder encoder = new HexDumpEncoder();
                        "[ " + encoder.encodeBuffer(encodedCertPair[i]) + " ]");

        return certPairs;

    public Certificate engineGenerateCertificate(InputStream is)
        throws CertificateException
        if (is == null) {
            throw new CertificateException("Missing input stream");
        try {
            byte[] encoding = readOneBlock(is);
            if (encoding != null) {
                X509CertImpl cert = getFromCache(certCache, encoding);
                if (cert != null) {
                    return cert;
                cert = new X509CertImpl(encoding);
                addToCache(certCache, cert.getEncodedInternal(), cert);
                return cert;
            } else {
                throw new IOException("Empty input");
        } catch (IOException ioe) {
            throw new CertificateException("Could not parse certificate: " +
                    ioe.toString(), ioe);

This class represents an X.509 Certificate Pair object, which is primarily used to hold a pair of cr

oss certificates issued between Certification Authorities. The ASN.1 structure is listed below. The forward certificate of the CertificatePair contains a certificate issued to this CA by another CA. The reverse certificate of the CertificatePair contains a certificate issued by this CA to another CA. When both the forward and the reverse certificates are present in the CertificatePair, the issuer name in one certificate shall match the subject name in the other and vice versa, and the subject public key in one certificate shall be capable of verifying the digital signature on the other certificate and vice versa. If a subject public key in one certificate does not contain required key algorithm parameters, then the signature check involving that key is not done.

The ASN.1 syntax for this object is: CertificatePair ::= SEQUENCE { forward [0] Certificate OPTIONAL, reverse [1] Certificate OPTIONAL -- at least one of the pair shall be present --

This structure uses EXPLICIT tagging. References: Annex A of X.509(2000), X.509(1997). @author Sean Mullan @since 1.4

Read More