I am trying to convert publicKeyFromDongleData to SecKey, then perform some tasks. After that, I want to convert SecKey to b64 String. I am assuming that publicKeyFromDongleData and b64 string will be the same. But, surprisingly, they are not the same. How can i resolve the issue? Is there any way around?
My goal is to retain the public key before and after converting the same.
let publicKeyFromDongleData = Data.init(base64Encoded: publicKeyFromDongle)
guard let publicKeySecKey = SecKeyCreateWithData(publicKeyFromDongleData! as CFData, keyDict as CFDictionary, &error) else {
print("Failed to create public key:", error!.takeRetainedValue())
return nil
}
//var error:Unmanaged<CFError>?
if let cfdata = SecKeyCopyExternalRepresentation(publicKeySecKey, &error) {
let data:Data = cfdata as Data
let b64Key = data.base64EncodedString()
print("after : \n")
print(b64Key)
}