title: RSA public key encryption in Swift
body: <p>I have my public key included in the project as byte array. And I wanted to encrypt password using it.When I tried to create  public key from the byte array I am getting the below given error.</p>
  
  <pre><code>SecKeyCreateWithData failed :Optional(Swift.Unmanaged&lt;__ObjC.CFError&gt;(_value: Error Domain=NSOSStatusErrorDomain Code=-50
  "RSA public key creation from data failed" UserInfo={NSDescription=RSA public key creation from data failed}))
  </code></pre>
  
  <p>Below given is the code.</p>
  
  <pre><code>let attributes : [String : Any] = [
  kSecAttrKeyType as String :  kSecAttrKeyTypeRSA,
  kSecAttrKeyClass as String : kSecAttrKeyClassPublic,
  kSecAttrKeySizeInBits as String : 1024 as AnyObject]
  
  var priKeyCreateError: Unmanaged&lt;CFError&gt;?
  _ = SecKeyCreateWithData(PublicKeyDataDevQA as Data as CFData, attributes as CFDictionary, &amp;priKeyCreateError)
  
  if(priKeyCreateError != nil)
  {
      print("\n SecKeyCreateWithData failed :" + String(describing: priKeyCreateError));
  }
  </code></pre>
  
  <p>I want to implement this without using any third party library like Swifty RSA.</p>
  
  <p>Public Key used is available<a href="https://pastebin.com/QQMDRXLA" rel="nofollow noreferrer"> here </a> </p>