我正在做TripleDES加密和解密。收到此错误:
UnsafePointer<UInt8>' is not convertible to 'UnsafePointer<_>
我收到错误的代码是:
let keyString = "25d1d4cb0a08403e2acbcbe0"
let keyData = keyString.data(using: .utf8)!
let message = pass
let data = message.data(using: .utf8)!
let cryptData = NSMutableData(length: Int(data.count) + kCCBlockSize3DES)!
let keyLength = size_t(kCCKeySize3DES)
let operation: CCOperation = UInt32(kCCEncrypt)
let algoritm: CCAlgorithm = UInt32(kCCAlgorithm3DES)
let options: CCOptions = UInt32(kCCOptionECBMode + kCCOptionPKCS7Padding)
var numBytesEncrypted :size_t = 0
let cryptStatus = keyData.withUnsafeBytes { (keyBytes: UnsafePointer<UInt8>) in
data.withUnsafeBytes { (dataBytes: UnsafePointer<UInt8>) in
cryptData.withUnsafeMutableBytes { (cryptBytes: UnsafeMutablePointer<UInt8>) in
CCCrypt(operation,
algoritm,
options,
keyBytes,
keyLength,
nil,
dataBytes,
data.count,
cryptBytes,
cryptData.count,
&numBytesEncrypted)
}
}
}
有人可以帮忙吗?
最佳答案
此错误消息是某种编译器错误的结果:编译器无法编译代码,并发出无效且具有误导性的错误消息。另请参阅https://bugs.swift.org/browse/SR-5931
在大多数情况下,您可以:
<UInt8>
)以揭示真正原因关于ios - 'UnsafePointer <UInt8>'不能转换为'UnsafePointer <_>',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50742540/