Code example for CertificateException

      TrustManagerFactory tmf = TrustManagerFactory.getInstance("X509");
      return tmf.getTrustManagers();
    } catch (NoSuchAlgorithmException nsae) {
      throw new CertificateException(nsae);
    } catch (KeyStoreException e) {
      throw new CertificateException(e);
  private boolean isValidPin(X509Certificate certificate) throws CertificateException {
    try { 
      byte[] spki          = certificate.getPublicKey().getEncoded();	        	
      MessageDigest digest = MessageDigest.getInstance("SHA1");
      byte[] pin           = digest.digest(spki);
      for (byte[] validPin : this.pins) {
	if (Arrays.equals(validPin, pin))
	  return true; 
Connect your IDE to all the code out there  Get Codota for Java