Sample code for 30+ languages & platforms
Java Requires Chilkat v11.0.0+

Get Base64 Public Key from Private Key

See more ECC Examples

Demonstrates how to get the public key in base64 format from a private key.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.BinData;
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.PrivateKey;
import com.chilkatsoft.chilkat2.PublicKey;

public class ChilkatExample {

    public static void main(String[] args) {
        // Load a private key from base64.
        BinData bd = new BinData();
        bd.appendEncoded("MHQCA....n0Q==", "base64");

        PrivateKey privKey = new PrivateKey();
        try {
            privKey.loadAnyFormat(bd, "");
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        PublicKey pubKey = new PublicKey();
        privKey.toPublicKey(pubKey);

        String pubKeyBase64 = pubKey.getEncoded(true, "base64");
        System.out.println(pubKeyBase64);
    }
}