(Java) Get Base64 Public Key from Private Key
Demonstrates how to get the public key in base64 format from a private key. Note: This example requires Chilkat v11.0.0 or greater.
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[])
{
boolean success = false;
// Load a private key from base64.
CkBinData bd = new CkBinData();
success = bd.AppendEncoded("MHQCA....n0Q==","base64");
CkPrivateKey privKey = new CkPrivateKey();
success = privKey.LoadAnyFormat(bd,"");
if (success == false) {
System.out.println(privKey.lastErrorText());
return;
}
CkPublicKey pubKey = new CkPublicKey();
privKey.ToPublicKey(pubKey);
String pubKeyBase64 = pubKey.getEncoded(true,"base64");
System.out.println(pubKeyBase64);
}
}
|