code: public static boolean validCertificateString(String certificateString) {
      try {
        byte[] certBytes = parseDERFromPEM(certificateString, CERT_START, CERT_END);
        generateCertificateFromDER(certBytes);
      } catch (Exception e) {
        return false;
      }
      return true;
    }
docs: Checks the given certificate String to ensure it is a PEM formatted certificate.
  
  @param certificateString The certificate String.
  @return True if the certificate String is valid, false if it isn't (this happens when an exception is thrown
  attempting to parse the PEM format).