I have to protect my lock from MITM (i.e man in the middle attack). For that i have to integrate ECDH encryption
. I have no knowledge related to this. Please help me how do i create 64 bytes public
and 32 byte private
key. below are the code i'm trying
var publicKeySec, privateKeySec: SecKey?
let keyattribute = [
kSecAttrKeyType as String: kSecAttrKeyTypeEC,
kSecAttrKeySizeInBits as String : 256
] as CFDictionary
SecKeyGeneratePair(keyattribute, &publicKeySec, &privateKeySec)
var error:Unmanaged<CFError>?
if let publicCfdata = SecKeyCopyExternalRepresentation(publicKeySec!, &error) {
let data:Data = publicCfdata as Data
print(data)
let b64Key = data.base64EncodedString()
print(b64Key)
}
if let privateCfdata = SecKeyCopyExternalRepresentation(privateKeySec!, &error) {
let data:Data = privateCfdata as Data
print(data)
let b64Key = data.base64EncodedString()
print(b64Key)
}
Please help me. Thanks in advance.