我必须保护我的锁免受 MITM(即中间人攻击)。为此,我必须整合ECDH encryption
。我没有这方面的知识。请帮助我如何创建64 bytes public
和32 byte private
键入。下面是我正在尝试的代码
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)
}
请帮我。提前致谢。