title: Swift 4: kSecMatchIssuers keychain search query failing to match X.509 certificate
body: <p>I have a query designed to search for an identity in my keychain so I can delete it from within my swift application. I need to be able to match it by the issuer so I'm making use of the kSecMatchIssuers key in the search query. The apple developer portal states this for matching with kSecMatchIssuers:</p>
  
  <blockquote>
    <p>The corresponding value is of type CFArray, where the array consists of X.500 names of type CFData. If provided, returned certificates or identities are limited to those whose certificate chain contains one of the issuers provided in this list.</p>
  </blockquote>
  
  <p>I believe I am following these guidelines, but am still failing to match the identity, even when I reduce the x.500 name to its barebones at "o=myOrg".</p>
  
  <pre><code> let x500Name = "o=myOrg"
  
   let nameAsData = x500Name.data(using: .utf8)! as CFData
  
  
   let query: [String: Any] = [kSecClass as String: kSecClassIdentity,
                                   kSecMatchCaseInsensitive as String: true,
                                   kSecMatchLimit as String: kSecMatchLimitAll,
                                   kSecMatchIssuers as String: [nameAsData] as CFArray]
  </code></pre>
  
  <p>When putting the query into SecItemCopyMatching as a CFDictionary, the return value is a code stating no matching values found. Simply removing the kSecMatchIssuers ensures everything runs and it finds all identities in my keychain. I'm at a bit of a loss as to what I'm passing in incorrectly here, as the keychain definitely contains identities with "o=myOrg". </p>
  
  <p>Any help is appreciated.</p>