I create a Certificate Path with Java.
It is presented as an object CertPath and then as a Base64 string for output.
// certificates that build a chain: rootcert -> intermediatecert -> mycert
X509Certificate rootcert = ...
X509Certificate intermediatecert = ...
X509Certificate mycert = ...
CertPathBuilder cpb = CertPathBuilder.getInstance ("PKIX");
X509CertSelector xcs = new X509CertSelector ();
xcs.setCertificate (mycert);
Set <TrustAnchor> trusts = new HashSet <> ();
trusts.add (new TrustAnchor (rootcert, null));
X509Certificate cc [] = new X509Certificate [1];
cc [0] = intermediatecert;
CertStore cs = CertStore.getInstance ("Collection", new CollectionCertStoreParameters (Arrays.asList (cc)));
PKIXBuilderParameters pbp = new PKIXBuilderParameters (trusts, xcs);
pbp.addCertStore (cs);
pbp.setRevocationEnabled(false);
CertPath certPath = cpb.build (pbp).getCertPath ();
// Base64 encoded string of the certificate chain/path
String b64str = Base64.getMimeEncoder ().encodeToString (certPath.getEncoded ());
System.out.println (b64str);
If I parse the Base64 string (e.g. put it into a file and then
openssl asn1parse -in myfile
) it represents a sequence of X509 certificates in ASN1 – as expected – so far, so good.
Now the question is: how can I go the reverse way? From Base64-String to CertPath object??
I do not see any possible way to init CertPath or CertPathBuilder with a byte-array.
Do I need to parse ASN1 manually or is there a Creator/Builder for this?