ECDSAKeyGenerator implements KeyGenerator<ECDSAKey> { public PrivateKey createPrivateKey(final BigInteger d) throws Exception { final KeyFactory factory = KeyFactory.getInstance(KEY_ALGORITHM); final ECPrivateKeySpec spec = new ECPrivateKeySpec(d, ecSpec); return factory.generatePrivate(spec); }  @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 testCreatePrivateKey() throws Exception { final ECDSAKeyGenerator generator = new ECDSAKeyGenerator(); final ECDSAKey key = generator.create(); final org.bouncycastle.jce.interfaces.ECPrivateKey ecPrivateKey = (org.bouncycastle.jce.interfaces.ECPrivateKey) key.getPrivateKey(); final PrivateKey recovered = generator.createPrivateKey(ecPrivateKey.getD()); assertEquals(ecPrivateKey.getD(), ((org.bouncycastle.jce.interfaces.ECPrivateKey) recovered).getD()); }