I am working on an android project for school and I am supposed to do a DHKE(Diffie Hellman Key Exchange). Everything works well, the problem is that it takes a lot of time (really a lot) to generate DHParameters. Basically, in my code, this is the part that is the most time (and battery) consuming:
KeyPairGenerator kpgDH = KeyPairGenerator.getInstance("DH"); kpgDH.initialize(512); KeyPair kpDH = kpgDH.generateKeyPair();
As you can see, the key length is only 512 bits, so it's not long, and it still takes at least 30-40 seconds (best case scenario), but it can go up to 400 seconds. And I've tested it on several phones: Samsung galaxy s2 (quad core), samsung galaxy s4 (quad core), samsung galaxy note 10.1 (quad core). Does anybody know an alternative to generate more quickly the p and g for the Diffie Hellman in order to speed-up the process?