Where did you have "key" defined? Check if it really exists: if(key) { ... I think key is not defined or NULL ?
EXC_BAD_ACCESS code=1 on SecKeyGetBlockSize()
-
18-10-2022 - |
سؤال
Im trying to add a key into the keychain then encrypt data with it.
NSData* peerTag = [@"Test PublicKey" dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary * peerPublicKeyAttr = [NSDictionary dictionaryWithObjectsAndKeys:
(__bridge id)kSecClassKey, kSecClass,
(__bridge id)kSecAttrKeyTypeRSA, kSecAttrKeyType,
(__bridge id)kSecAttrKeyClassPublic, kSecAttrKeyClass,
peerTag, kSecAttrApplicationTag,
testPubKey, kSecValueData,
kCFBooleanTrue, kSecReturnPersistentRef,
nil];
OSStatus sanityCheck = noErr;
sanityCheck = SecItemDelete((__bridge CFDictionaryRef) peerPublicKeyAttr);
SecKeyRef persistPeer = NULL;
sanityCheck = SecItemAdd((__bridge CFDictionaryRef)peerPublicKeyAttr, (CFTypeRef *)&persistPeer);
NSData* passwordData = [@"password" dataUsingEncoding:NSUTF8StringEncoding];
NSData* encryptedPass = [[Methods sharedCenter]encrypt:passwordData usingKey:persistPeer];
size_t cipherBufferSize = SecKeyGetBlockSize(persistPeer);
SecKeyGetBlockSize(key);
causes EXC_BAD_ACCESS code=1.
I have not worked with this before so im not sure what would cause this error. What am i doing wrong here?
المحلول
لا تنتمي إلى StackOverflow