SecKeyCopyKeyExchangeResult
调用会抛出下一个错误,无论提供了什么参数。在iOS 13.0上运行正常。
缺少kSecKeyKeyExchangeParameterParameterededSize
我的代码:
// Parameter value set here
let params = [SecKeyKeyExchangeParameter.requestedSize: 32, SecKeyKeyExchangeParameter.sharedInfo:Data()] as [SecKeyKeyExchangeParameter : Any]
// Function call:
let sharedSecret = try? generateSharedSecret(issuerPublicKey: issuerPublicKey!, parameters: params as [SecKeyKeyExchangeParameter : Any])
// Function
func generateSharedSecret(issuerPublicKey: SecKey, devicePrivateKey: SecKey, parameters:[SecKeyKeyExchangeParameter: Any] = [:]) throws -> Data? {
var error: Unmanaged<CFError>?
guard let shared = SecKeyCopyKeyExchangeResult(devicePrivateKey, .ecdhKeyExchangeCofactorX963SHA384, issuerPublicKey, parameters as CFDictionary, &error) else {
throw error!.takeRetainedValue() as Error
}
return shared as Data
}
参数数据:
▿ 2 elements
▿ 0 : 2 elements
▿ key : SecKeyKeyExchangeParameter
- rawValue : requestedSize
- value : 32
▿ 1 : 2 elements
▿ key : SecKeyKeyExchangeParameter
- rawValue : sharedInfo
▿ value : 0 bytes
- count : 0
▿ pointer : 0x000000016db58ac0
- pointerValue : 6135581376
- bytes : 0 elements
错误:
▿ Optional<Unmanaged<CFErrorRef>>
▿ some : Unmanaged<CFErrorRef>
- _value : Error Domain=NSOSStatusErrorDomain Code=-50 "kSecKeyKeyExchangeParameterRequestedSize is missing" UserInfo={NSDescription=kSecKeyKeyExchangeParameterRequestedSize is missing}
答案 0 :(得分:0)
将SecKeyKeyExchangeParameter.requestedSize
更改为SecKeyKeyExchangeParameter.requestedSize.rawValue
。