use of io.nem.symbol.core.crypto.KeyGenerator in project nem2-sdk-java by nemtech.
the class Ed25519KeyGeneratorTest method derivePublicKey.
@Test
public void derivePublicKey() {
final KeyGenerator generator = this.getKeyGenerator();
final KeyPair keyPair = KeyPair.fromPrivate(PrivateKey.fromHexString("787225aaff3d2c71f4ffa32d4f19ec4922f3cd869747f267378f81f8e3fcb12d"));
final PublicKey publicKey = generator.derivePublicKey(keyPair.getPrivateKey());
final PublicKey expected = PublicKey.fromHexString("2134E47AEE6F2392A5B3D1238CD7714EABEB739361B7CCF24BAE127F10DF17F2");
MatcherAssert.assertThat(publicKey, IsEqual.equalTo(expected));
}
use of io.nem.symbol.core.crypto.KeyGenerator in project nem2-sdk-java by nemtech.
the class Ed25519KeyGeneratorTest method derivePublicKeyReturnsExpectedPublicKey.
@Test
public void derivePublicKeyReturnsExpectedPublicKey() {
// Arrange:
final KeyGenerator generator = this.getKeyGenerator();
for (int i = 0; i < 100; i++) {
final KeyPair kp = generator.generateKeyPair();
// Act:
final PublicKey publicKey1 = generator.derivePublicKey(kp.getPrivateKey());
final PublicKey publicKey2 = MathUtils.derivePublicKey(kp.getPrivateKey());
// Assert:
MatcherAssert.assertThat(publicKey1, IsEqual.equalTo(publicKey2));
}
}
use of io.nem.symbol.core.crypto.KeyGenerator in project nem2-sdk-java by nemtech.
the class Ed25519KeyGeneratorTest method derivedPublicKeyIsValidPointOnCurve.
@Test
public void derivedPublicKeyIsValidPointOnCurve() {
// Arrange:
final KeyGenerator generator = this.getKeyGenerator();
for (int i = 0; i < 100; i++) {
final KeyPair kp = generator.generateKeyPair();
// Act:
final PublicKey publicKey = generator.derivePublicKey(kp.getPrivateKey());
// Assert (throws if not on the curve):
Ed25519GroupElement decode = new Ed25519EncodedGroupElement(publicKey.getBytes()).decode();
Assertions.assertNotNull(decode);
}
}
Aggregations