How To Generate Parameter Set for the Diffie-Hellman Key Agreement Algorithm in Android

Posted by sebby_zml on Stack Overflow See other posts from Stack Overflow or by sebby_zml
Published on 2010-05-13T01:14:01Z Indexed on 2010/05/13 1:44 UTC
Read the original article Hit count: 347

Filed under:
|
|

Hello everyone,

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.

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.

My question is is there anything wrong with the code or it is not compactible for android?What kind of changes should I do?
Your suggestion and guidance would be very much help for me. Thanks a lot in advance.

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;
}

Regards,
Sebby

© Stack Overflow or respective owner

Related posts about diffiehellman

Related posts about java