ECDSAKeyGenerator implements KeyGenerator<ECDSAKey> { @Override public ECDSAKey create() throws Exception { return generateKey(new SecureRandom()); }  @Override ECDSAKey create(); ECDSAKey create(final String seed); ECDSAKey create(final byte[] encodedPrivateKey); ECDSAKey create(final BigInteger d); ECDSAKey create(final PrivateKey privateKey); PrivateKey createPrivateKey(final BigInteger d); PublicKey createPublicKey(final byte[] compressed); PublicKey createPublicKey(final BigInteger x, final BigInteger y); static final ECDomainParameters ecParams; }
@Test public void testCreate() throws Exception { final ECDSAKeyGenerator generator = new ECDSAKeyGenerator(); final ECDSAKey key = generator.create(); assertNotNull(key.getPrivateKey()); assertNotNull(key.getPublicKey()); final ECDSAKey arrayRecovered = generator.create(key.getPrivateKey().getEncoded()); logger.debug("Private Key:\n{}", dump(key.getPrivateKey().getEncoded())); logger.debug("Recovered private key:\n{}", dump(arrayRecovered.getPrivateKey().getEncoded())); assertArrayEquals(key.getPrivateKey().getEncoded(), arrayRecovered.getPrivateKey().getEncoded()); logger.debug("Public Key:\n{}", dump(key.getPublicKey().getEncoded())); logger.debug("Recovered public key:\n{}", dump(arrayRecovered.getPublicKey().getEncoded())); assertArrayEquals(key.getPublicKey().getEncoded(), arrayRecovered.getPublicKey().getEncoded()); final ECDSAKey keyRecovered = generator.create(key.getPrivateKey()); logger.debug("Private Key:\n{}", dump(key.getPrivateKey().getEncoded())); logger.debug("Recovered private key:\n{}", dump(keyRecovered.getPrivateKey().getEncoded())); assertArrayEquals(key.getPrivateKey().getEncoded(), keyRecovered.getPrivateKey().getEncoded()); logger.debug("Public Key:\n{}", dump(key.getPublicKey().getEncoded())); logger.debug("Recovered public key:\n{}", dump(keyRecovered.getPublicKey().getEncoded())); assertArrayEquals(key.getPublicKey().getEncoded(), keyRecovered.getPublicKey().getEncoded()); }
@Test public void testCreateWithSeed() throws Exception { final ECDSAKeyGenerator generator = new ECDSAKeyGenerator(); final String seed = randomUUID().toString(); ECDSAKey prev = generator.create(seed); for (int i = 1; i < 100; ++i) { final ECDSAKey curr = generator.create(seed); assertEquals(curr, prev); prev = curr; } }