I am trying to detect the content of a PEM file. In case it contains certificate infos, the following code is perfect to get X509Certificates informations:
X509Certificate cert = X509CertUtils.parse(Files.readAllBytes(file.toPath()));
but returns NULL
of course if it's a key instead of certificate.
So is there a proper way to detect PEM content (mayb PEMReader
and then instance of on the result. I tried with a ---- PRIVATE KEY -----
file but it returned null also)?
Of course, I can manually detect if file contain -----BEGIN CERTIFICATE-----
or -----BEGIN PRIVATE KEY-----
but I find this very careless.
Thank you !