You can get the X and Y (where Y = G^X mod P
) values like this:
BigInteger x = ((javax.crypto.interfaces.DHPrivateKey) dkp.getPrivate()).getX();
BigInteger y = ((javax.crypto.interfaces.DHPublicKey) dkp.getPublic()).getY();
You can get the G and P values from either the public or private key like this:
DHParameterSpec params =
((javax.crypto.interfaces.DHPublicKey) dkp.getPublic()).getParams();
BigInteger p = params.getP();
BigInteger g = params.getG();
From there you can get them all as raw byte arrays:
byte[] xBytes = x.toByteArray();
byte[] yBytes = y.toByteArray();
byte[] pBytes = p.toByteArray();
byte[] gBytes = g.toByteArray();
The combination of Y, P, and G make the public key. X should be kept secret.