@Immutable public final class CertificateHelper extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
BEGIN_CERTIFICATE |
static String |
BEGIN_CERTIFICATE_INVALID |
static Charset |
CERT_CHARSET
Character set used for String-Certificate conversion
|
static String |
CRLF |
static String |
END_CERTIFICATE |
static String |
END_CERTIFICATE_INVALID |
| Modifier and Type | Method and Description |
|---|---|
static X509Certificate |
convertByteArrayToCertficate(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 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() |
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 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 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 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 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.Copyright © 2016–2019 Philip Helger. All rights reserved.