code: public static boolean isSelfSigned(X509Certificate cert,
          String sigProvider) {
          if (isSelfIssued(cert)) {
              try {
                  if (sigProvider == null) {
                      cert.verify(cert.getPublicKey());
                  } else {
                      cert.verify(cert.getPublicKey(), sigProvider);
                  }
                  return true;
              } catch (Exception e) {
                  // In case of exception, return false
              }
          }
          return false;
      }
docs: Utility method to test if a certificate is self-signed. This is
  the case iff the subject and issuer X500Principals are equal
  AND the certificate's subject public key can be used to verify
  the certificate. In case of exception, returns false.