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...
JCEECPublicKey pubKey = (JCEECPublicKey)kp.getPublic();
if (!compress)
{
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]);
JCEECPrivateKey privateECKey = (JCEECPrivateKey)kp.getPrivate();
keyStore.setKeyEntry("ECPrivKey", privateECKey, keyStorePass
.toCharArray(), chain);
// Test ec sign / verify
JCEECPublicKey pub = (JCEECPublicKey)kp.getPublic();
String oldPrivateKey = new String(Hex.encode(privateECKey.getEncoded()));
String oldPublicKey = new String(Hex.encode(pub.getEncoded()));
JCEECPrivateKey newKey = (JCEECPrivateKey)keyStore.getKey("ECPrivKey",
keyStorePass.toCharArray());
JCEECPublicKey newPubKey = (JCEECPublicKey)keyStore.getCertificate(
"ECCert").getPublicKey();
if (!compress)
{
newKey.setPointFormat("UNCOMPRESSED");
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");
}