我对iOS上的加密技术还很陌生,并且遇到了一个我无法找到解决方案的错误:
[每当我尝试在iOS钥匙串中获取对公共密钥的SecKeyRef并使用它时,我都会遇到EXC_BAD_ACCESS错误。 SecKeyRef(在我下面的代码中称为“ publicKeyReference”,最初设置为NULL,但是在调用SecItemCopyMatching方法之后,它应该具有一个值,可以从调试器窗口的内存地址中看到它。)>
这是我的代码:
SecKeyRef publicKeyReference = NULL; NSData* publicTag = [publicKeyIdentifier dataUsingEncoding:NSUTF8StringEncoding]; NSMutableDictionary *queryPublicKey = [[NSMutableDictionary alloc] init]; // Set the public key query dictionary. [queryPublicKey setObject:(__bridge id)kSecClassKey forKey:(__bridge id)kSecClass]; [queryPublicKey setObject:publicTag forKey:(__bridge id)kSecAttrApplicationTag]; [queryPublicKey setObject:(__bridge id)kSecAttrKeyTypeRSA forKey:(__bridge id)kSecAttrKeyType]; [queryPublicKey setObject:[NSNumber numberWithBool:YES] forKey:(__bridge id)kSecReturnPersistentRef]; // Get the key. sanityCheck = SecItemCopyMatching((__bridge CFDictionaryRef)queryPublicKey, (CFTypeRef *)&publicKeyReference); // Encrypt using the public. sanityCheck = SecKeyEncrypt( publicKeyReference, PADDING, plainBuffer, plainBufferSize, &cipherBuffer[0], &cipherBufferSize );
这是错误和调试窗口的一些屏幕截图:
<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9xSm1odS5wbmcifQ==” alt =“错误的代码的Xcode版本”>“>
似乎已将某些内容分配给SecKeyRef,因为地址的值不是“ 0x0”,但是无论我尝试了什么,我一直在不断遇到EXC_BAD_ACCESS错误。在此问题上,我们将提供任何帮助。
我对iOS上的加密技术还很陌生,并且遇到了一个我无法找到解决方案的错误:每当我尝试在iOS钥匙串中尝试将SecKeyRef转换为公钥时,使用它,...
我在使用SecKeyCreateEncryptedData
函数时遇到了相同的错误(该错误旨在替换iOS 10+上的SecKeyEncrypt
的用法),这不是由SecKeyRef
引起的,而是由CFDataRef
加密的数据引起的。因此,我建议检查加密的数据,例如plainBuffer
,plainBufferSize
等。>