Java Requires Chilkat v11.0.0+
Chilkat2 Java
Duplicate openssl pkey -in private.pem -pubout -out pubkey.pem
See more OpenSSL Examples
How to output the public part of a private key: Demonstrates how to duplicate this OpenSSL command:openssl pkey -in private.pem -pubout -out pubkey.pem
Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.PrivateKey;
import com.chilkatsoft.chilkat2.PublicKey;
public class ChilkatExample {
public static void main(String[] args) {
PrivateKey pkey = new PrivateKey();
// Load the private key from an PEM file:
try {
pkey.loadPemFile("private.pem");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
PublicKey pubKey = new PublicKey();
pkey.toPublicKey(pubKey);
try {
pubKey.savePemFile(false, "pubKey.pem");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
pubKey.close();
return;
}
System.out.println("Success.");
}
}