IOS 9: SecItemCopyMatching returns a successful status code, but the key is zero

I try to import the private key into keychain using the SecItemAdd method returns OSStatus 0, but when I try to extract this key from the keychain using SecItemCopyMatch , it returns nil data, but OSStatus is 0 means success

Please refer to the Apple developers forum link

+4
source share
2 answers

The error occurs due to an invalid public key. https://forums.developer.apple.com/thread/15129

If you are using the Basic Encoding Rules library of rules here.

To fix your public key, you need to insert a zero byte in front of the module data. https://github.com/StCredZero/SCZ-BasicEncodingRules-iOS/issues/6#issuecomment-136601437

PS For me, the fix was as simple as:

 const char fixByte = 0; NSMutableData * fixedModule = [NSMutableData dataWithBytes:&fixByte length:1]; [fixedModule appendData:modulusData]; 
+1
source

Thanks! you are my hero!

In my case.

  • Before

     NSData *modBits = [[NSData alloc] initWithBase64EncodedString:mod options:NSDataBase64DecodingIgnoreUnknownCharacters]; 
  • After

     const char fixByte = 0; NSMutableData * modBits = [NSMutableData dataWithBytes:&fixByte length:1]; NSData *tmpmodBits = [[NSData alloc] initWithBase64EncodedString:mod options:NSDataBase64DecodingIgnoreUnknownCharacters]; [modBits appendData:tmpmodBits]; 
+1
source

All Articles