你可以得到X和Y(其中Y = G ^ X mod P)的值如下:
BigInteger x = ((javax.crypto.interfaces.DHPrivateKey) dkp.getPrivate()).getX();
BigInteger y = ((javax.crypto.interfaces.DHPublicKey) dkp.getPublic()).getY();
您可以从公钥或私钥获取G和P值,如下所示:
DHParameterSpec params =
((javax.crypto.interfaces.DHPublicKey) dkp.getPublic()).getParams();
BigInteger p = params.getP();
BigInteger g = params.getG();
从那里你可以将它们全部作为原始字节数组:
byte[] xBytes = x.toByteArray();
byte[] yBytes = y.toByteArray();
byte[] pBytes = p.toByteArray();
byte[] gBytes = g.toByteArray();
公共密钥是Y,P和G的组合. X应该保密.