I want ssl to pin the public key to swift, I read a lot of examples of how to do this, and the last thing I can not find is how to compare the two public keys in the SecKey object format. Example:
let serverPublicKey = SecTrustCopyPublicKey(secTrust) /*return SecKey object from actual SecTrust*/
let clientPublicKey = getLocalPublicKeyFromDer() /*return SecKey from .der local*/
how to compare them? I am doing this now and it works:
if(serverPublicKey! as AnyObject).isEqual(clientPublicKey){
}
find a way on gitHub: https://github.com/teamcarma/IOS-AlamofireDomain/blob/master/Source/ServerTrustPolicy.swift
but casting to AnyObject is a good idea? How does isEqual work on cast SecKey? Can anyone explain me?
ps. Another idea is to get base64 from SecKey - I try, and it works too, but it requires temporary KeyChain operations, and they don't look professional.