Skip to main content
1 of 2
Frank Kong
  • 700
  • 1
  • 6
  • 16

I posted my own answer here in case someone else has the question. Web3j provides a ECKeyPair as util to process key and address conversion. Please see codes below:

        String privateKey = "{your private key}";
        Credentials cs = Credentials.create(privateKey);
        
        String privateKey = cs.getEcKeyPair().getPrivateKey().toString(16);
        String publicKey = cs.getEcKeyPair().getPublicKey().toString(16);
        String addr = cs.getAddress();
        
        System.out.println("Private key: " + privateKey);
        System.out.println("Public key: " + publicKey);
        System.out.println("Address: " + addr);
Frank Kong
  • 700
  • 1
  • 6
  • 16