0

I am making a native ios module for yandexnavi. The module has been successfully created and I am passing geolocation data to it. Next, I use the code from the Yandex instructions. But I am getting an error - Fatal error: Unexpectedly found nil while unwrapping an Optional value. At the end of the function:

func loadCert() -> SecKey {
  let certificateData = NSData(
    contentsOf:Bundle.main.url(forResource: "private_key", withExtension: "der")!
  )

  let options: [String: Any] =
    [kSecAttrKeyType as String: kSecAttrKeyTypeRSA,
    kSecAttrKeyClass as String: kSecAttrKeyClassPrivate,
    kSecAttrKeySizeInBits as String: 512]

  let key = SecKeyCreateWithData(certificateData!,
    options as CFDictionary,
    nil)
  return key! //Fatal error: Unexpectedly found nil while unwrapping an Optional value.
}

It seems that the key file is not correct, but if the resource file is not correct, then I get a completely different error

The sent Yandex key *.pen was previously converted to *.der

openssl rsa -in key.pem -out key.der -outform DER
Witexp
  • 1
  • 1
  • 1
    Does this answer your question? [What does "Fatal error: Unexpectedly found nil while unwrapping an Optional value" mean?](https://stackoverflow.com/questions/32170456/what-does-fatal-error-unexpectedly-found-nil-while-unwrapping-an-optional-valu) – koen Aug 19 '22 at 10:01
  • what is the output of the `openssl` command? – Raptor Aug 22 '22 at 02:10

0 Answers0