One of the goals of Keychain is to keep secret keys without exposing their data to the application. To prevent accidental disclosure of the private key, by default these elements are marked CSSM_KEYATTR_EXTRACTABLE | CSSM_KEYATTR_SENSITIVE CSSM_KEYATTR_EXTRACTABLE | CSSM_KEYATTR_SENSITIVE ; that is, their data can only be obtained using SecKeychainItemExport and only in a format protected by a passphrase.
The security structure has APIs that encrypt / decrypt / sign / verify, etc. data using the supplied key element, without putting the primary key data in the address space of the application. (These operations are usually performed by a separate, privileged process.)
If for some reason you need access to the raw bits of a private key, you need to prepare for this when you import the private key into the key chain. You need to set keyAttributes to CSSM_KEYATTR_EXTRACTABLE (i.e. Without a sensitive bit) in the keyParams SecKeychainItemImport parameter.
source share