title: Key generation failed iOS 15 simulator Xcode13
body: <p>Error Domain=NSOSStatusErrorDomain Code=-4 &quot;Key generation failed, error -4&quot; UserInfo={numberOfErrorsDeep=0, NSDescription=Key generation failed, error -4} during creation private key</p>
  <pre><code>let tag = &quot;com.qwerty.www&quot;.data(using: .utf8)!
          
          let attributes: [String: Any] =
              [kSecAttrKeyType as String : type(of: kSecAttrKeyType),
               kSecAttrKeySizeInBits as String:      2048,
               kSecPrivateKeyAttrs as String:
                  [kSecAttrIsPermanent as String:    true,
                   kSecAttrApplicationTag as String: tag]
          ]
          
          var error: Unmanaged&lt;CFError&gt;?
          guard let privateKey = SecKeyCreateRandomKey(attributes as CFDictionary, &amp;error) else {
              print(error!.takeRetainedValue() as Error)
              return
          }
          
          let publicKey = SecKeyCopyPublicKey(privateKey)
  
  </code></pre>