Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think the part of the example</p> <pre><code>private static BigInteger g512 = new BigInteger("1234567890", 16); private static BigInteger p512 = new BigInteger("1234567890", 16); </code></pre> <p>is completely bogus. <code>p</code> needs to be prime and <code>g</code>needs to be a generator. When I try running the example I get an exception. <a href="http://www.exampledepot.com/egs/javax.crypto/KeyAgree.html" rel="nofollow">This</a> seems to be a more reasonable example (but I haven't tested it myself yet).</p> <p>Basically the interesting input to the DH exchange is that (<code>p,g</code>) pair which needs to be generated and must have some unique properties. Clearly, the example above shows just place holder values which will not produce a correctly functioning algorithm (<code>p</code> can not be equal to <code>g</code> and <code>p</code> should be prime, while in the example it is clearly divisible by 10). The example I linked to shows how to use the libraries to generate a correct (<code>p, g</code>) pair. </p> <p>It is also worth noting that DH parameter generation is usually a separate step from generating the secret key. While DH parameters are somewhat private, they are not as sensitive as your private key and can be generated once and then reused.</p> <p><strong>(Edit: <a href="http://www.exampledepot.com/egs/javax.crypto/GenDhParams.html" rel="nofollow">Example</a>)</strong></p> <pre><code>AlgorithmParameterGenerator paramGen = AlgorithmParameterGenerator.getInstance("DH"); paramGen.init(512); // number of bits AlgorithmParameters params = paramGen.generateParameters(); DHParameterSpec dhSpec = params.getParameterSpec(DHParameterSpec.class); BigInteger p512 = dhSpec.getP(); BigInteger g512 = dhSpec.getG(); int l = dhSpec.getL(); ... </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload