(Java) Get Base64 Public Key from Private Key
Demonstrates how to get the public key in base64 format from a private key.
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[])
{
// Load a private key from base64.
CkBinData bd = new CkBinData();
boolean 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 = privKey.GetPublicKey();
if (privKey.get_LastMethodSuccess() == false) {
System.out.println(privKey.lastErrorText());
return;
}
String pubKeyBase64 = pubKey.getEncoded(true,"base64");
System.out.println(pubKeyBase64);
}
}
|