gpt4 book ai didi

ios - 无法使用类型为“(UInt32, UnsafePointer, UInt, [CChar], Int, UnsafeMutablePointer) 的参数列表调用 'CCHmac'

转载 作者:行者123 更新时间:2023-11-28 07:07:49 24 4
gpt4 key购买 nike

我将 xCode 和/或 swift 1.0 更新为 1.2,但出现了很多错误,

我知道 Swift 1.2 中的一些方法已更新/更改,因此我开始将我的整个项目更新到 Swift 1.2。我被困在这条线上:

CCHmac(CCHmacAlgorithm(kCCHmacAlgSHA1), cKey, strlen(cKey), str!, strLen, result)

抛出错误 Cannot invoke 'CCHmac' with an argument list of type '(UInt32, UnsafePointer<Int8>, UInt, [CChar], Int, UnsafeMutablePointer<CUnsignedChar>)'

这是我的代码

.
.
.
let str = cred.cStringUsingEncoding(NSUTF8StringEncoding)
let strLen:Int = Int(cred.lengthOfBytesUsingEncoding(NSUTF8StringEncoding))
let digestLen = Int(CC_SHA1_DIGEST_LENGTH)
let result = UnsafeMutablePointer<CUnsignedChar>.alloc(digestLen)
let objcKey = key as NSString
let keyStr = Key.cStringUsingEncoding(NSUTF8StringEncoding)
let keyLen:Int = Int(Key.lengthOfBytesUsingEncoding(NSUTF8StringEncoding))

var st:NSString = dataFromHexadecimalString(Key)!
let cKey = st.cStringUsingEncoding(NSUTF8StringEncoding)


CCHmac(CCHmacAlgorithm(kCCHmacAlgSHA1), cKey, strlen(cKey), str!, strLen, result)
.
.
.

注意:我改了keyLenstrLen来自 Uint to Int但它仍然抛出相同的错误。

最佳答案

我解决了它只是将 strlen(cKey) 转换为 int 就像 Int(strlen(cKey))

整行看起来是

CCHmac(CCHmacAlgorithm(kCCHmacAlgSHA1), cKey, Int(strlen(cKey)), str!, strLen, result)

关于ios - 无法使用类型为“(UInt32, UnsafePointer<Int8>, UInt, [CChar], Int, UnsafeMutablePointer<CUnsignedChar>) 的参数列表调用 'CCHmac',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29816842/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com