@Immutable public final class CertificateHelper extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
BEGIN_CERTIFICATE |
static String |
BEGIN_CERTIFICATE_INVALID |
static String |
BEGIN_PRIVATE_KEY |
static Charset |
CERT_CHARSET
Character set used for String-Certificate conversion
|
static String |
CRLF |
static String |
END_CERTIFICATE |
static String |
END_CERTIFICATE_INVALID |
static String |
END_PRIVATE_KEY |
| Modifier and Type | Method and Description |
|---|---|
static X509Certificate |
convertByteArrayToCertficate(byte[] aCertBytes)
Convert the passed byte array to an X.509 certificate object.
|
static X509Certificate |
convertByteArrayToCertficateDirect(byte[] aCertBytes)
Convert the passed String to an X.509 certificate without converting it to
a String first.
|
static X509Certificate |
convertByteArrayToCertficateOrNull(byte[] aCertBytes)
Convert the passed byte array to an X.509 certificate object.
|
static byte[] |
convertCertificateStringToByteArray(String sCertificate)
Convert the passed X.509 certificate string to a byte array.
|
static X509Certificate |
convertStringToCertficate(String sCertString)
Convert the passed String to an X.509 certificate.
|
static X509Certificate |
convertStringToCertficateOrNull(String sCertString)
Convert the passed String to an X.509 certificate, swallowing all errors.
|
static PrivateKey |
convertStringToPrivateKey(String sPrivateKey) |
static byte[] |
getEncodedCertificate(Certificate aCert)
Get the provided certificate as a byte array.
|
static String |
getPEMEncodedCertificate(Certificate aCert)
Get the provided certificate as PEM (Base64) encoded String.
|
static String |
getRFC1421CompliantString(String sCertificate,
boolean bIncludePEMHeader)
The certificate string needs to be emitted in portions of 64 characters.
|
static String |
getRFC1421CompliantString(String sCertificate,
boolean bIncludePEMHeader,
String sLineSeparator)
The certificate string needs to be emitted in portions of 64 characters.
|
static String |
getWithoutPEMHeader(String sCertificate)
Remove any eventually preceding "-----BEGIN CERTIFICATE-----" and succeeding
"-----END CERTIFICATE-----" values from the passed certificate string.
|
static String |
getWithPEMHeader(String sCertString) |
static CertificateFactory |
getX509CertificateFactory() |
static boolean |
isCertificateValidPerNow(X509Certificate aCert)
Check if the "not valid before"/"not valid after" of the provided X509
certificate is valid per "now".
|
public static final String BEGIN_CERTIFICATE
public static final String END_CERTIFICATE
public static final String BEGIN_CERTIFICATE_INVALID
public static final String END_CERTIFICATE_INVALID
public static final String BEGIN_PRIVATE_KEY
public static final String END_PRIVATE_KEY
public static final String CRLF
public static final Charset CERT_CHARSET
@Nonnull public static CertificateFactory getX509CertificateFactory() throws CertificateException
CertificateException@Nullable public static String getWithoutPEMHeader(@Nullable String sCertificate)
sCertificate - The source certificate string. May be null.null if the input string is null or
empty, the stripped down string otherwise.@Nullable public static String getRFC1421CompliantString(@Nullable String sCertificate, boolean bIncludePEMHeader)
sCertificate - Original certificate string as stored in the DBbIncludePEMHeader - true to include BEGIN_CERTIFICATE header and
END_CERTIFICATE footer.null if the
original string is null or empty.@Nullable public static String getRFC1421CompliantString(@Nullable String sCertificate, boolean bIncludePEMHeader, @Nonnull String sLineSeparator)
sCertificate - Original certificate string as stored in the DBbIncludePEMHeader - true to include BEGIN_CERTIFICATE header and
END_CERTIFICATE footer.sLineSeparator - The line separator to be used. May not be null. Usually
this is "\r\n" but may also be just "\n".null if the
original string is null or empty.@Nullable public static X509Certificate convertByteArrayToCertficate(@Nullable byte[] aCertBytes) throws CertificateException
aCertBytes - The original certificate bytes. May be null or empty.null if the passed byte array is null or
emptyCertificateException - In case the passed string cannot be converted to an X.509
certificate.@Nullable public static X509Certificate convertByteArrayToCertficateOrNull(@Nullable byte[] aCertBytes)
aCertBytes - The original certificate bytes. May be null or empty.null if the passed byte array is null,
empty or not a valid certificate.@Nullable public static X509Certificate convertByteArrayToCertficateDirect(@Nullable byte[] aCertBytes) throws CertificateException
aCertBytes - The certificate bytes. May be null.null if the passed array is null or emptyCertificateException - In case the passed bytes[] cannot be converted to an X.509
certificate.@Nullable public static X509Certificate convertStringToCertficate(@Nullable String sCertString) throws CertificateException
sCertString - The original text string. May be null or empty. The
String must be ISO-8859-1 encoded for the binary certificate to be
read!null if the passed string is null or
emptyCertificateException - In case the passed string cannot be converted to an X.509
certificate.IllegalArgumentException - If the input string is e.g. invalid Base64 encoded.@Nullable public static X509Certificate convertStringToCertficateOrNull(@Nullable String sCertString)
sCertString - The certificate string to be parsed.null in case the certificate cannot be converted.convertStringToCertficate(String)@Nullable public static byte[] convertCertificateStringToByteArray(@Nullable String sCertificate)
sCertificate - The original certificate string. May be null or empty.null if the passed string is null or
empty or an invalid Base64 string@Nonnull @Nonempty public static byte[] getEncodedCertificate(@Nonnull Certificate aCert)
aCert - The certificate to encode. May not be null.IllegalArgumentException - If the certificate could not be encoded. Cause is a
CertificateEncodingException.@Nonnull @Nonempty public static String getPEMEncodedCertificate(@Nonnull Certificate aCert)
aCert - The certificate to encode. May not be null.BEGIN_CERTIFICATE and
END_CERTIFICATE.IllegalArgumentException - If the certificate could not be encoded. Cause is a
CertificateEncodingException.public static boolean isCertificateValidPerNow(@Nonnull X509Certificate aCert)
aCert - The certificate to check. May not be null.true if it is valid, false if not.@Nullable public static PrivateKey convertStringToPrivateKey(@Nullable String sPrivateKey) throws GeneralSecurityException
GeneralSecurityExceptionCopyright © 2016–2021 Philip Helger. All rights reserved.