title: Java SHA1WithRSA using openssl command line
body: <p>I have the following piece of Java code that I would like to convert to a shell script using openssl command line tool:</p>
  
  <pre><code>java.security.Signature sig = java.security.Signature.getInstance("SHA1WithRSA");
  sig.initSign(privateKey);
  sig.update(data);
  byte[] signatureBytes = sig.sign();
  </code></pre>
  
  <p>So far I have tried the following:</p>
  
  <pre><code>openssl dgst -sha1 -binary &lt; data.der &gt; data.hash
  openssl rsautl -sign -inkey private.key -keyform pem -in data.hash -out data.rsa
  </code></pre>
  
  <p>However it does not produce the same output. I guess it might have something to do with formats or padding etc. What do I need to do to correct the openssl script?</p>
  
  <p>Both codes above produce a repeatable result but the result is different between java and the openssl shell script.</p>
  
  <p>All suggestions are appreciated.</p>
  
  <p>Kind regards
  Jens</p>