use of com.helger.commons.io.stream.NonBlockingByteArrayInputStream in project as2-server by phax.
the class ImportCertInEncodedStreamCommand method _importCert.
private CommandResult _importCert(final IAliasedCertificateFactory certFx, final String alias, final String encodedCert) throws CertificateException, OpenAS2Exception {
final NonBlockingByteArrayInputStream bais = new NonBlockingByteArrayInputStream(ByteCoder.decode(encodedCert).getBytes());
final CertificateFactory cf = CertificateFactory.getInstance("X.509");
while (bais.available() > 0) {
final Certificate cert = cf.generateCertificate(bais);
if (cert instanceof X509Certificate) {
certFx.addCertificate(alias, (X509Certificate) cert, true);
final CommandResult cmdRes = new CommandResult(ECommandResultType.TYPE_OK, "Certificate(s) imported successfully");
cmdRes.addResult("Imported certificate: " + cert.toString());
return cmdRes;
}
}
return new CommandResult(ECommandResultType.TYPE_ERROR, "No valid X509 certificates found");
}
Aggregations