@@ -0,0 +1,2717 @@
+package de.alpharogroup.crypto.key.reader;%0A%0Aimport java.io.ByteArrayInputStream;%0Aimport java.io.File;%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.nio.file.Files;%0Aimport java.security.cert.CertificateException;%0Aimport java.security.cert.CertificateFactory;%0Aimport java.security.cert.X509Certificate;%0A%0Aimport org.apache.commons.codec.binary.Base64;%0A%0Aimport lombok.experimental.UtilityClass;%0A%0A/**%0A * The class %7B@link CertificateReader%7D is a utility class for reading%0A * certificates.%0A */%0A@UtilityClass%0Apublic class CertificateReader %7B%0A%0A%09/** The Constant END_CERTIFICATE_SUFFIX. */%0A%09public static final String END_CERTIFICATE_SUFFIX = %22-----END CERTIFICATE-----%22;%0A%0A%09/** The Constant BEGIN_CERTIFICATE_PREFIX. */%0A%09public static final String BEGIN_CERTIFICATE_PREFIX = %22-----BEGIN CERTIFICATE-----%5Cn%22;%0A%0A%09/**%0A%09 * Read pem certificate.%0A%09 *%0A%09 * @param file%0A%09 *            the file%0A%09 * @param securityProvider%0A%09 *            the security provider%0A%09 * @return the certificate%0A%09 * @throws Exception%0A%09 *             is thrown if if a security error occur%0A%09 */%0A%09public static X509Certificate readPemCertificate(final File file) throws Exception %7B%0A%09%09final String privateKeyAsString = readPemFileAsBase64(file);%0A%09%09final byte%5B%5D decoded = new Base64().decode(privateKeyAsString);%0A%09%09return readCertificate(decoded);%0A%09%7D%0A%0A%09/**%0A%09 * Read the certificate from a pem file as base64 encoded %7B@link String%7D%0A%09 * value.%0A%09 *%0A%09 * @param file%0A%09 *            the file in pem format that contains the public key.%0A%09 * @return the base64 encoded %7B@link String%7D value.%0A%09 * @throws IOException%0A%09 *             Signals that an I/O exception has occurred.%0A%09 */%0A%09public static String readPemFileAsBase64(final File file) throws IOException %7B%0A%09%09final byte%5B%5D keyBytes = Files.readAllBytes(file.toPath());%0A%09%09final String publicKeyAsBase64String = new String(keyBytes).replace(BEGIN_CERTIFICATE_PREFIX, %22%22)%0A%09%09%09%09.replace(END_CERTIFICATE_SUFFIX, %22%22);%0A%09%09return publicKeyAsBase64String;%0A%09%7D%0A%0A%09/**%0A%09 * Reads the given byte array and tries to create a %7B@link X509Certificate%7D object.%0A%09 *%0A%09 * @param decoded%0A%09 *            the decoded%0A%09 * @return the %7B@link X509Certificate%7D object from the given byte array.%0A%09 * @throws CertificateException%0A%09 *             is thrown if no Provider supports a CertificateFactorySpi%0A%09 *             implementation for the specified type.%0A%09 */%0A%09public static X509Certificate readCertificate(byte%5B%5D decoded) throws CertificateException %7B%0A%09%09CertificateFactory certificateFactory = CertificateFactory.getInstance(%22X.509%22);%0A%09%09InputStream inputStream = new ByteArrayInputStream(decoded);%0A%09%09X509Certificate certificate = (X509Certificate) certificateFactory.generateCertificate(inputStream);%0A%09%09return certificate;%0A%09%7D%0A%0A%7D%0A

Create CertificateReader.java