title: How To Generate Parameter Set for the Diffie-Hellman Key Agreement Algorithm in Android
body: <p>I am working on mobile/server security related project. I am now stuck in generating a Diffie-Hellman key agreement part. It works fine in server side program but it is not working in mobile side. Thus, I assume that it is not compactible with Android.</p>
  
  <p>I used the following class to get the parameters. It returns a comma-separated string of 3 values. The first number is the prime modulus P. The second number is the base generator G. The third number is bit size of the random exponent L.  </p>
  
  <p><em>My question is is there anything wrong with the code or it is not compactible for android?What kind of changes should I do?</em><br>
  Your suggestion and guidance would be very much help for me. Thanks a lot in advance.</p>
  
  <pre><code>public static String genDhParams() {
   try {
  // Create the parameter generator for a 1024-bit DH key pair
  AlgorithmParameterGenerator paramGen = AlgorithmParameterGenerator.getInstance("DH");
  paramGen.init(1024);
  // Generate the parameters
  AlgorithmParameters params = paramGen.generateParameters();
  DHParameterSpec dhSpec = (DHParameterSpec)params.getParameterSpec(DHParameterSpec.class);
  // Return the three values in a string
  return ""+dhSpec.getP()+","+dhSpec.getG()+","+dhSpec.getL();
  } catch (NoSuchAlgorithmException e) {
  } catch (InvalidParameterSpecException e) {
  }
  return null;
  }
  </code></pre>
  
  <p>Regards,<br>
  <em>Sebby</em></p>