title: URL Signing with HMAC or OpenSSL
body: <p>I'm interested in url signing (e.g. <a href="http://.../?somearg=value&amp;anotherarg=anothervalue&amp;sig=aSKS9F3KL5xc" rel="noreferrer">http://.../?somearg=value&amp;anotherarg=anothervalue&amp;sig=aSKS9F3KL5xc</a>), but I have a few requirements which have left me without a solution yet.</p>
  
  <ul>
  <li>I'll be using either <code>PHP</code> or <code>Python</code> for pages, so I'll need to be able to sign and verify a signature using one of the two.</li>
  <li>My plan was to use a priv/pub key scheme to sign some data, and be able to verify that the signature is valid, but here's where it gets complicated:</li>
  <li>The data is not known when the verification is happening (it is not just <code>somearg=value&amp;anotherarg=anothervalue</code>)</li>
  </ul>
  
  <p>My first instinct was to use OpenSSL, e.g. with a RSA keypair, to do something along the lines of signing by: <code>openssl rsautl -sign -inkey private.pem -in sensitive -out privsigned</code>   and verifying based on the <code>privsigned</code> data and key ONLY: <code>openssl rsautl -verify -inkey public.pem -in privsigned -pubin</code>.</p>
  
  <p>Using PHP's <code>openssl_get_privatekey()</code> and <code>openssl_sign()</code> signs the data just fine, but I need to know the (decrypted!) data in order to verify (which I will not have): <code>openssl_get_publickey()</code> and <code>openssl_verify($data, $signature, $pubkeyid);</code> from <a href="http://php.net/openssl_verify" rel="noreferrer">http://php.net/openssl_verify</a>.</p>
  
  <p>Or am I missing something here?</p>
  
  <hr>
  
  <p>So I looked into HMAC, but although many hash function are available in both <code>Python</code> and <code>PHP</code>, I'm baffled as to how I'd go about <strong><em>verifying</em></strong> the hash.
  <code>PHP</code>'s <code>hash_hmac()</code> allows me to create a hash using a "key" (or in this case a string-key). But how do I go about verifying that a hash is valid (i.e. <code>&amp;sig=</code> hasn't just been manually put in by the end user <code>&amp;sig=abcdefg1234</code>.</p>
  
  <p>So to sum up (sorry for the long question): How can I verify that a signature/hash has been made by my server's (cert/string)key (given I can not verify by redoing the hash of said data)? And do you have any preferences as to which route I should chose, Priv/pub-key or HMAC?</p>
  
  <p>Any pointers big or small is greatly appreciated!
  Thanks in advance,</p>
  
  <ul>
  <li>Josh</li>
  </ul>