params.getG(), params.getN(), params.getH(), params
.getSeed()));
kp = kpg.generateKeyPair();
// The very old Problem... we need a certificate chain to
// save a private key...
ECPublicKey pubKey = (ECPublicKey)kp.getPublic();
if (!compress)
{
((ECPointEncoder)pubKey).setPointFormat("UNCOMPRESSED");
}
byte[] x = pubKey.getQ().getX().toBigInteger().toByteArray();
byte[] y = pubKey.getQ().getY().toBigInteger().toByteArray();
if (x.length == y.length)
{
success = true;
}
}
// The very old Problem... we need a certificate chain to
// save a private key...
Certificate[] chain = new Certificate[] { generateSelfSignedSoftECCert(
kp, compress) };
KeyStore keyStore = KeyStore.getInstance("BKS");
keyStore.load(null, keyStorePass.toCharArray());
keyStore.setCertificateEntry("ECCert", chain[0]);
ECPrivateKey privateECKey = (ECPrivateKey)kp.getPrivate();
keyStore.setKeyEntry("ECPrivKey", privateECKey, keyStorePass
.toCharArray(), chain);
// Test ec sign / verify
ECPublicKey pub = (ECPublicKey)kp.getPublic();
String oldPrivateKey = new String(Hex.encode(privateECKey.getEncoded()));
String oldPublicKey = new String(Hex.encode(pub.getEncoded()));
ECPrivateKey newKey = (ECPrivateKey)keyStore.getKey("ECPrivKey",
keyStorePass.toCharArray());
ECPublicKey newPubKey = (ECPublicKey)keyStore.getCertificate(
"ECCert").getPublicKey();
if (!compress)
{
((ECPointEncoder)newKey).setPointFormat("UNCOMPRESSED");
((ECPointEncoder)newPubKey).setPointFormat("UNCOMPRESSED");
}
String newPrivateKey = new String(Hex.encode(newKey.getEncoded()));
String newPublicKey = new String(Hex.encode(newPubKey.getEncoded()));
if (!oldPrivateKey.equals(newPrivateKey))
{
fail("failed private key comparison");
}