Swift
Swift
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 Swift Downloads
func chilkatTest() {
var success: Bool = false
// Load a private key from base64.
let bd = CkoBinData()!
success = bd.appendEncoded(encData: "MHQCA....n0Q==", encoding: "base64")
let privKey = CkoPrivateKey()!
success = privKey.loadAnyFormat(privKeyData: bd, password: "")
if success == false {
print("\(privKey.lastErrorText!)")
return
}
let pubKey = CkoPublicKey()!
privKey.toPublicKey(pubKey: pubKey)
var pubKeyBase64: String? = pubKey.getEncoded(preferPkcs1: true, encoding: "base64")
print("\(pubKeyBase64!)")
}