title: Issues with computing shared secret of Diffie Hellman key for OpenID
body: <p>I'm attempting to create a stateful library for OpenID to be used as a Wordpress plugin, I'm running into a issue when I attempt to compute the secret value using the openssl function <a href="http://php.net/manual/en/function.openssl-dh-compute-key.php" rel="nofollow noreferrer">openssl_dh_compute_key</a>. Curious if anyone has some steps I could try, hints, etc...</p>
  
  <p>Thanks!</p>
  
  <p>The constants...</p>
  
  <pre><code>const DH_DEFAULT_PRIME = "dcf93a0b883972ec0e19989ac5a2ce310e1d37717e8d9571bb7623731866e61ef75a2e27898b057f9891c2e27a639c3f29b60814581cd3b2ca3986d2683705577d45c2e7e52dc81c7a171876e5cea74b1448bfdfaf18828efd2519f14e45e3826634af1949e5b535cc829a483b8a76223e5d490a257f05bdff16f2fb22c583ab";
  const DH_DEFAULT_GENERATOR = '02';
  </code></pre>
  
  <p>Creating my Diffie-Hellman key</p>
  
  <pre><code>private function createDHKey($priv_key = false) {
      if (!$priv_key) {
          $details = array();
          $details['p'] = pack('H*', self::DH_DEFAULT_PRIME);
          $details['g'] = pack('H*', self::DH_DEFAULT_GENERATOR);
          $this-&gt;dh = openssl_pkey_new(array(
              'dh' =&gt; $details,
          ));
          if ($this-&gt;dh) {
              return true;
          } else {
              error('OpenSSL failed to export your private key, ensure you have a valid configuration file, and PHP can find it.');
          }
      } else {
          $this-&gt;dh = openssl_pkey_get_private($priv_key);
          return false;
      }
  }
  </code></pre>
  
  <p><img src="https://i.imgur.com/bCasc.png" alt="First run of function"></p>
  
  <p><img src="https://i.imgur.com/p1VG4.png" alt="Recalling exported private key"></p>
  
  <p>The Ag== at the button of both images is the base64 encoded value of dh['g'].</p>
  
  <p>I then save the generated private key into a database to persist, which allows me to later re-create the key via the openssl_pkey_get_private function.</p>
  
  <p>However, taking the returned openid.dh_server_public from the association request, and passing it, and my key re-created from the private key results in a false for </p>
  
  <pre><code>var_dump(openssl_dh_compute_key($this-&gt;op_pubkey, $this-&gt;dh));
  </code></pre>