Code example for CertificateException

0
      TrustManagerFactory tmf = TrustManagerFactory.getInstance("X509");
      tmf.init((KeyStore)null);
 
      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; 
      }