EdDsaKeyGenerator implements KeyGenerator { @Override public PublicKey derivePublicKey(PrivateKey privateKey) { if (privateKey == null) { throw new IllegalArgumentException("PrivateKey must not be null."); } PublicKeyDelegate delegate = schemeProvider.getPublicKeyDelegate(); byte[] publicKeySeed = delegate.generatePublicKeySeed(privateKey); return new PublicKey(publicKeySeed); } EdDsaKeyGenerator(SchemeProvider schemeProvider); @Override EdKeyAnalyzer getKeyAnalyzer(); @Override KeyPair generateKeyPair(); @Override KeyPair generateKeyPair(PrivateKey privateKey); @Override PublicKey derivePublicKey(PrivateKey privateKey);  }
@Test public void success_GeneratePublicKey_from_all_zero_byte32() { byte[] seed = new byte[32]; PrivateKey privateKey = PrivateKeyEd25519.fromBytes(seed); PublicKey publicKey = generator.derivePublicKey(privateKey); assertThat(publicKey.getHexString(), is("462ee976890916e54fa825d26bdd0235f5eb5b6a143c199ab0ae5ee9328e08ce")); }
@Test public void generate() { PrivateKey privateKey = PrivateKeyEd25519.fromHexString("cdf762a91a9932fe755d1e62e1eabf94111d3fe9eafc191fe9cbedbd0902252c"); PublicKey publicKey = generator2.derivePublicKey(privateKey); assertThat(publicKey.getHexString(), is("18c484505c8f175bbdd511acde1faaea8e35a579cfc0d220f6d3513ebb4204b5")); }
@Test(expected = IllegalArgumentException.class) public void failure_GeneratePublicKey_Curve25519() { KeyGenerator generator = new Edwards().getKeyGenerator(); generator.derivePublicKey(null); }
@Test(expected = IllegalArgumentException.class) public void failure_GeneratePublicKey_Curve448() { SchemeProvider schemeProvider = new Ed448SchemeProvider(HashAlgorithm.SHAKE_256); KeyGenerator generator = new Edwards(schemeProvider).getKeyGenerator(); generator.derivePublicKey(null); }