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posZcz/0cPpjNFUyAyeyvSYbD2HusE
sbuMzHnSTFia5P5d32LtqD9tK7L3fS5d7NXa4Aod36JECqbKYyWInnWs3R3jFtKW
PGIA/V82oDQTvg9ey4fAvBrAUKfO3/UxF844k9cfCo1xrNxWv37wFuzuYbjA9w6Y
xiYWElRfRaEwChu+/2A2jYJ76lAOvbAyfILYNTtditM=
-----END CERTIFICATE-----
I'm using the following code.
CertificateFactory certFactory = CertificateFactory.getInstance(CERTIFICATE_TYPE, JCE_PROVIDER);
fileInputStream = new FileInputStream(new File(publicKeyFileName));
X509Certificate cert = (X509Certificate) certFactory.generateCertificate(fileInputStream);
publicKey = cert.getPublicKey();
certExpiryDate = cert.getNotAfter();
But this only work, if I provide the certificate as somename.cer file.