Bouncy castle - how to rebuild Public key from EdDSA

418 views Asked by At

I have Edward curve key parameters - x, d and curve. How can I rebuild PublicKey/Private keys using bouncy castle?

1

There are 1 answers

0
Eduard Semsch On

If x is your public key, d is your private key and curve is Curve25519 or Curve448, then you can simply do the following:

final BigInteger x = ...;  // here is your public key as an integer
final BigInteger d = ...;  // here is your private key as an integer

final Ed25519PrivateKeyParameters reconstructedPrivateKey = new Ed25519PrivateKeyParameters(d.toByteArray(), 0);
final Ed25519PublicKeyParameters reconstructedPublicKey = new Ed25519PublicKeyParameters(x.toByteArray(), 0);

This is an example of getting Ed25519 public/private keys, for X25519, Ed448, or X448 you just need to use their respective classes instead.