@Nullable
  public static X509Certificate convertStringToCertficate (@Nullable final String sCertString) throws CertificateException
  {
    if (StringHelper.hasNoText (sCertString))
    {
      // No string -> no certificate
      return null;
    }

    final CertificateFactory aCertificateFactory = getX509CertificateFactory ();

    // Convert certificate string to an object
    try
    {
      return _str2cert (sCertString, aCertificateFactory);
    }
    catch (final IllegalArgumentException | CertificateException ex)
    {
      // In some weird configurations, the result string is a hex encoded
      // certificate instead of the string
      // -> Try to work around it
      if (LOGGER.isDebugEnabled ())
        LOGGER.debug ("Failed to decode provided X.509 certificate string: " + sCertString);

      String sHexDecodedString;
      try
      {
        sHexDecodedString = new String (StringHelper.getHexDecoded (sCertString), CERT_CHARSET);
      }
      catch (final IllegalArgumentException ex2)
      {
        // Can happen, when the source string has an odd length (like 3 or 117).
        // In this case the original exception is rethrown
        throw ex;
      }

      return _str2cert (sHexDecodedString, aCertificateFactory);
    }
  }
@ Nullable public static X509Certificate convertStringToCertficate ( @ Nullable final String sCertString ) throws CertificateException { if ( StringHelper . hasNoText ( sCertString ) ) { return null ; } final CertificateFactory aCertificateFactory = getX509CertificateFactory ( ) ; try { return _str2cert ( sCertString , aCertificateFactory ) ; } catch ( final IllegalArgumentException | CertificateException ex ) { if ( LOGGER . isDebugEnabled ( ) ) LOGGER . debug ( "Failed to decode provided X.509 certificate string: " + sCertString ) ; String sHexDecodedString ; try { sHexDecodedString = new String ( StringHelper . getHexDecoded ( sCertString ) , CERT_CHARSET ) ; } catch ( final IllegalArgumentException ex2 ) { throw ex ; } return _str2cert ( sHexDecodedString , aCertificateFactory ) ; } }
Convert the passed String to an X.509 certificate.

@param sCertString
The original text string. May be <code>null</code> or empty. The
String must be ISO-8859-1 encoded for the binary certificate to be
read!
@return <code>null</code> if the passed string is <code>null</code> or
empty
@throws CertificateException
In case the passed string cannot be converted to an X.509
certificate.
@throws IllegalArgumentException
If the input string is e.g. invalid Base64 encoded.