0
我有檢索和存儲RSAkeydataCFDictionaryCreate崩潰3
下面的代碼fileprivate func retrieveAndStoreRSAKeyData(isPublic: Bool) throws -> CFData {
var resultCode = noErr
var result: CFData
let value = {
if isPublic {
let t = self.publicTag
print(t)
}
else
{
let s = self.privateTag
print(s)
}
}
var keyCallbacks = kCFTypeDictionaryKeyCallBacks
var valueCallbacks = kCFTypeDictionaryValueCallBacks
let keys = [Unmanaged.passUnretained(kSecClass).toOpaque(), Unmanaged.passUnretained(kSecAttrApplicationTag).toOpaque(), Unmanaged.passUnretained(kSecAttrKeyType).toOpaque(), Unmanaged.passUnretained(kSecReturnData).toOpaque()]
let values = [Unmanaged.passUnretained(kSecClassKey).toOpaque(), Unmanaged<AnyObject>.passUnretained(value as AnyObject).toOpaque(), Unmanaged.passUnretained(kSecAttrKeyTypeRSA).toOpaque(), Unmanaged.passUnretained(kCFBooleanTrue).toOpaque()]
let queryKey = CFDictionaryCreate(kCFAllocatorDefault,UnsafeMutablePointer.allocate(capacity: keys.count),UnsafeMutablePointer.allocate(capacity: values.count), 4, &keyCallbacks, &valueCallbacks)
// Get the key.
var item: AnyObject?
resultCode = SecItemCopyMatching(queryKey!, &item)
if(resultCode != noErr) {
try generateKeyPair()
/*
Recurcively call the retrieval again after keys have been generated
*/
result = try retrieveAndStoreRSAKeyData(isPublic: isPublic)
}
else {
result = item as! CFData
}
return result
}
的CFDictionaryCreate總是
失敗,代碼崩潰在這行 let queryKey = CFDictionaryCreate(kCFAllocatorDefault,UnsafeMutablePointer.allocate(capacity: keys.count),UnsafeMutablePointer.allocate(capacity: values.count), 4, &keyCallbacks, &valueCallbacks)
有人可以幫助我在這。在此先感謝
https://stackoverflow.com/a/43902566/3441734 – user3441734