title: Server certificate hash code changes between java versions
body: <p>I am testing the following code to lookup certificate hash code on my machine and then run the same code on a different vm with java 7. </p>
  
  <p>I am puzzled to see the difference on hash code.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>import javax.net.ssl.HttpsURLConnection;
  import java.net.URL;
  import java.security.cert.Certificate;
  
  public class Main {
  
  public static void main(String[] args) throws Exception {
      HttpsURLConnection urlc = (HttpsURLConnection) new URL("https://www.google.com").openConnection();
      print_https_cert(urlc);
  }
  
  
  private static void print_https_cert(HttpsURLConnection con) {
  
      if (con != null) {
  
          try {
  
              System.out.println("Response Code : " + con.getResponseCode());
              System.out.println("Cipher Suite : " + con.getCipherSuite());
              System.out.println("\n");
  
              Certificate[] certs = con.getServerCertificates();
              for (Certificate cert : certs) {
                  System.out.println("Cert Type : " + cert.getType());
                  System.out.println("Cert Hash Code : " + cert.hashCode());
                  System.out.println("Cert Public Key Algorithm : "
                          + cert.getPublicKey().getAlgorithm());
                  System.out.println("Cert Public Key Format : "
                          + cert.getPublicKey().getFormat());
                  System.out.println("\n");
              }
  
          } catch (Exception e) {
              e.printStackTrace();
          }
  
      }
  }
  }
  </code></pre>
  
  <p><strong>Here's what I get with java 1.7.0_79</strong></p>
  
  <blockquote>
    <p>Response Code : 200</p>
    
    <p>Cipher Suite : TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA</p>
    
    <p>Cert Type : X.509 Cert Hash Code : 10920939 Cert Public Key Algorithm
    : RSA Cert Public Key Format : X.509</p>
    
    <p>Cert Type : X.509 Cert Hash Code : 6561088 Cert Public Key Algorithm :
    RSA Cert Public Key Format : X.509</p>
    
    <p>Cert Type : X.509 Cert Hash Code : 8774863 Cert Public Key Algorithm :
    RSA Cert Public Key Format : X.509</p>
  </blockquote>
  
  <p><strong>and here's the output with java 1.8.0_77</strong></p>
  
  <blockquote>
    <p>Response Code : 200 Cipher Suite :
    TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256</p>
    
    <p>Cert Type : X.509 Cert Hash Code : -106561125 Cert Public Key
    Algorithm : RSA Cert Public Key Format : X.509</p>
    
    <p>Cert Type : X.509 Cert Hash Code : 771393018 Cert Public Key Algorithm
    : RSA Cert Public Key Format : X.509</p>
    
    <p>Cert Type : X.509 Cert Hash Code : 349192256 Cert Public Key Algorithm
    : RSA Cert Public Key Format : X.509</p>
  </blockquote>
  
  <p>Should the hash code be same or am I missing something here ?</p>