What does OSStatus Error -50 mean?

10,451

Solution 1

It's errSecParam, indicating one or more of your parameters is wrong.

Here: https://developer.apple.com/library/ios/documentation/Security/Reference/keychainservices/index.html#//apple_ref/c/econst/errSecParam

Solution 2

If you are adding a password to the keychain make sure you pass it as Data and not String, otherwise you will get an OSStatus error -50.

static func savePassword(password: Data, account: String) throws -> OSStatus {
    let query = [
        kSecClass as String: kSecClassGenericPassword as String,
        kSecAttrAccount as String: account,
        kSecValueData as String: password
        ] as [String: Any]

    SecItemDelete(query as CFDictionary)

    return SecItemAdd(query as CFDictionary, nil)
}

Solution 3

Error -50 is a errSecParam, and means that at least one of the parameters you passed in a function was/are not valid.

This can be due to type differences, or perhaps an invalid value. See this page on the Apple site to read the official documentation from Apple on errSecParam.

Share:
10,451
zumzum
Author by

zumzum

Updated on June 04, 2022

Comments

  • zumzum
    zumzum almost 2 years

    I am writing some keychain code on iOS. When I try to insert an item in keychain I get error -50.

    What does OSStatus error -50 mean?

  • Chetan
    Chetan about 5 years
    SecItemDelete(query as CFDictionary) the line which resolved my issue, Thanks :)