//
// public key encoding test
//
byte[] pubEnc = aKeyPair.getPublic().getEncoded();
KeyFactory keyFac = KeyFactory.getInstance(algName, "BC");
X509EncodedKeySpec pubX509 = new X509EncodedKeySpec(pubEnc);
DHPublicKey pubKey = (DHPublicKey)keyFac.generatePublic(pubX509);
DHParameterSpec spec = pubKey.getParams();
if (!spec.getG().equals(dhParams.getG()) || !spec.getP().equals(dhParams.getP()))
{
fail(size + " bit public key encoding/decoding test failed on parameters");
}
if (!((DHPublicKey)aKeyPair.getPublic()).getY().equals(pubKey.getY()))
{
fail(size + " bit public key encoding/decoding test failed on y value");
}
//
// public key serialisation test
//
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
ObjectOutputStream oOut = new ObjectOutputStream(bOut);
oOut.writeObject(aKeyPair.getPublic());
ByteArrayInputStream bIn = new ByteArrayInputStream(bOut.toByteArray());
ObjectInputStream oIn = new ObjectInputStream(bIn);
pubKey = (DHPublicKey)oIn.readObject();
spec = pubKey.getParams();
if (!spec.getG().equals(dhParams.getG()) || !spec.getP().equals(dhParams.getP()))
{
fail(size + " bit public key serialisation test failed on parameters");
}
if (!((DHPublicKey)aKeyPair.getPublic()).getY().equals(pubKey.getY()))
{
fail(size + " bit public key serialisation test failed on y value");
}
//
// private key encoding test
//
byte[] privEnc = aKeyPair.getPrivate().getEncoded();
PKCS8EncodedKeySpec privPKCS8 = new PKCS8EncodedKeySpec(privEnc);
DHPrivateKey privKey = (DHPrivateKey)keyFac.generatePrivate(privPKCS8);
spec = privKey.getParams();
if (!spec.getG().equals(dhParams.getG()) || !spec.getP().equals(dhParams.getP()))
{