I want to convert ECPublicKey to PEM format as below
"-----BEGIN PUBLIC KEY-----MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEo0WcFrFClvBE8iZ1Gdlj+mTgZoJWMNE3kDKTfRny2iaguwuSYxo+jCnXqzkR+kyFK9CR3D+pypD1sGb1BnfWAA==-----END PUBLIC KEY-----"
- Generated ECPublicKey with key Type "ECC/ECDSA/spec256r1". Below is the print
<SecKeyRef curve type: kSecECCurveSecp256r1, algorithm id: 3, key type: ECPublicKey, version: 4, block size: 256 bits, y: B6EEBB3791933312E10BD7C3D65C950AB7E1C325BCDB57A8663EB7B1E29BFA77, x: 1D41FDAD2137316D415B117227BCC465566E56A54E7B2B9B3A4B66C15A067611, addr: 0x7f818850f6d0>
- To my knowledge PEM format is nothing but base64 encoded string along with header and footer. Tried below code, but no success
var error:Unmanaged<CFError>?
guard let cfdata = SecKeyCopyExternalRepresentation(publicKey, &error)
else { return }
let data:Data = cfdata as Data
let b64String = data.base64EncodedString()
Appreciate any help here