title: DSA algorithm : Sign in PHP
body: <p>I need to sign a data on my server in php, and verify the signed data on my Java desktop application. My issue is that I don't succeed to generate a key that both languages accept...</p>
  
  <p>My first try was to generate the key with Java <a href="https://docs.oracle.com/javase/7/docs/api/java/security/KeyPairGenerator.html" rel="nofollow noreferrer" title="KeyPairGenerator">KeyPairGenerator</a>, but as shown in <a href="https://stackoverflow.com/questions/37401519/signing-with-a-private-key-as-a-string-in-php" title="that question">that question</a>, I couldn't make openssl to read the key.</p>
  
  <p>Now I generated the keys with openssl like that :</p>
  
  <pre><code>$openssl dsaparam 512 &lt; /dev/random &gt; dsaparam.pem
  $openssl gendsa dsaparam.pem -out dsa_priv.pem
  $openssl dsa -in dsa_priv.pem -pubout -out dsa_pub.pem
  </code></pre>
  
  <p>I now try to sign something with this code :</p>
  
  <pre><code>&lt;?php
  $data = "test";
  
  $pkeyid = openssl_pkey_get_private("dsa_priv.pem");
  echo openssl_sign($data, $signature, $pkeyid);
  echo "&lt;br/&gt;";
  echo $signature;
  ?&gt;
  </code></pre>
  
  <p>Result ?</p>
  
  <pre><code>openssl_sign(): supplied key param cannot be coerced into a private key in ...
  </code></pre>
  
  <p>What am I doing wrong ? Can anyone help me generate a working DSA key and sign something with it ?</p>