title: Java deprecation of SHA-1 signatures: correct way to sign with SHA-256?
body: <p>In light of <a href="https://stackoverflow.com/questions/41878258/java-9-deprecating-sha1-certificates-or-another-issue-at-work">Java's deprecation of SHA-1 signed code</a>, I am transitioning to SHA-256. However, I am not sure whether, in order to comply with the new requirements, I should explicitly request the <code>-digestalg SHA-256</code> (if not, it sefaults to SHA-1, as per <a href="http://docs.oracle.com/javase/6/docs/technotes/tools/windows/jarsigner.html" rel="nofollow noreferrer">this</a>). (Side-note: although the public-private key pair in my JKS are <code>RSA</code>, I found I also had to explicitly ask <code>-sigalg SHA256withRSA</code>.)</p>
  
  <p>Java 9 "early access" seems to accept just fine the <code>SHA1</code> digest algorithm, as long as the signature algorithm is <code>SHA256withRSA</code>. I searched for a clear explanation of these exact terms (in the context...as reported by a <code>jarsigner</code> verification: "Digest algorithm", "Signature algorithm") / their implications, without too much success, though.</p>
  
  <p>The JREs I am targeting are 6 or better. Using Java 6 on the build machine as well.</p>
  
  <p>[L.E.] More confusingly for me, it seems that the jarsigner (in Java 9) verifies the jars (read: no complaints raised) even when both the digest algorithm and the signature algorithm are <code>SHA-1</code>, just on account that I have used an <code>SHA256</code> certificate.</p>
  
  <p>[L.E. 2] Interestingly, signing on Java 9 w/o providing any of the custom flags, and using the same JKS, everything is signed as expected:</p>
  
  <p><code>Digest algorithm: SHA-256
   Signature algorithm: SHA256withRSA, 2048-bit key</code></p>
  
  <p>I very much think this behavior underlines the "proper practice", rather than Java 6's. This may very well become the answer to this question...once Java 9 will be release. </p>
  
  <p>As another side-note, the <a href="https://www.java.com/en/jre-jdk-cryptoroadmap.html" rel="nofollow noreferrer">Java Crypto Roadmap</a> announces the same plan (<code>Disable SHA-1 in certificate chains anchored by roots included by default in Oracle's JDK; local or enterprise CAs are not affected. Signed code that is timestamped before 2017-01-01 is not affected.</code>) for Java 6, 7, 8 as well.</p>