(Java) Duplicate openssl pkey -in private.pem -pubout -out pubkey.pem
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
import com.chilkatsoft.*;
public class ChilkatExample {
static {
try {
System.loadLibrary("chilkat");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
CkPrivateKey pkey = new CkPrivateKey();
// Load the private key from an PEM file:
boolean success = pkey.LoadPemFile("private.pem");
if (success != true) {
System.out.println(pkey.lastErrorText());
return;
}
CkPublicKey pubKey = pkey.GetPublicKey();
if (pkey.get_LastMethodSuccess() == false) {
System.out.println(pkey.lastErrorText());
return;
}
success = pubKey.SavePemFile(false,"pubKey.pem");
if (success != true) {
System.out.println(pubKey.lastErrorText());
return;
}
System.out.println("Success.");
}
}
|