private void init() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException,
InvalidParameterSpecException, InvalidKeySpecException {
AlgorithmParameterGenerator pgen = AlgorithmParameterGenerator.getInstance("DH");
pgen.init(512);
AlgorithmParameters params = pgen.generateParameters();
DHParameterSpec dhspec = (DHParameterSpec)params.getParameterSpec(DHParameterSpec.class);
KeyPairGenerator keypairgen = KeyPairGenerator.getInstance("DH");
keypairgen.initialize(dhspec);
keyPair = keypairgen.generateKeyPair();
p = dhspec.getP();