// Generate a keypair
DHBasicKeyPairGenerator dhGen = new DHBasicKeyPairGenerator();
dhGen.init(new DHKeyGenerationParameters(random, dhParams));
AsymmetricCipherKeyPair dhPair = dhGen.generateKeyPair();
// Store the public value to send to server
this.Yc = ((DHPublicKeyParameters)dhPair.getPublic()).getY();
// Calculate the shared secret
DHBasicAgreement dhAgree = new DHBasicAgreement();
dhAgree.init(dhPair.getPrivate());
BigInteger agreement = dhAgree.calculateAgreement(new DHPublicKeyParameters(Ys, dhParams));
this.pms = BigIntegers.asUnsignedByteArray(agreement);
}