g.initialize(null, new SecureRandom());
KeyPair p = g.generateKeyPair();
ECPrivateKey sKey = (ECPrivateKey)p.getPrivate();
ECPublicKey vKey = (ECPublicKey)p.getPublic();
KeyFactory fact = KeyFactory.getInstance("ECDSA", "BC");
vKey = (ECPublicKey)fact.generatePublic(new ECPublicKeySpec(vKey.getQ(), null));
sKey = (ECPrivateKey)fact.generatePrivate(new ECPrivateKeySpec(sKey.getD(), null));
testECDSA(sKey, vKey);
testBCParamsAndQ(sKey, vKey);
testEC5Params(sKey, vKey);
testEncoding(sKey, vKey);
ECPublicKey vKey2 = (ECPublicKey)fact.generatePublic(new ECPublicKeySpec(vKey.getQ(), ecSpec));
ECPrivateKey sKey2 = (ECPrivateKey)fact.generatePrivate(new ECPrivateKeySpec(sKey.getD(), ecSpec));
if (!vKey.equals(vKey2) || vKey.hashCode() != vKey2.hashCode())
{
fail("private equals/hashCode failed");
}
if (!sKey.equals(sKey2) || sKey.hashCode() != sKey2.hashCode())
{
fail("private equals/hashCode failed");
}
// check we can get specs.