Skip to content
Back to skills

Ios Security

ASecurity

Here’s a quick-start iOS security example that covers secure token storage, biometric unlock, and protected file writes: ```swift import Foundation import LocalAuthentication import Security enum SecureStore { static func saveToken(_ token: String, account: String = "authToken") throws { let data = Data(token.utf8) let query: [String: Any] = [ kSecClass as String: kSecClassGenericPassword, kSecAttrAccount as String: account, kSecValueData as String: data ] SecItemDelete(query as CFDictionary)...

  • 549 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 5, 2026
developmentswiftapisecurity

Works with

  • api

Security analysis

A100/100

Pro scans all 12 files and shows the line behind each finding

Scanned September 5, 2026

npx -y skills add HoangNguyen0403/agent-skills-standard --skill ios-security --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Ios Security?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Ios Security
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/hoangnguyen0403-ios-security-313131d1/badge)](https://www.skillsdirectory.com/skills/hoangnguyen0403-ios-security-313131d1)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
Here’s a quick-start iOS security example that covers secure token storage, biometric unlock, and protected file writes:

```swift
import Foundation
import LocalAuthentication
import Security

enum SecureStore {
    static func saveToken(_ token: String, account: String = "authToken") throws {
        let data = Data(token.utf8)
        let query: [String: Any] = [
            kSecClass as String: kSecClassGenericPassword,
            kSecAttrAccount as String: account,
            kSecValueData as String: data
        ]

        SecItemDelete(query as CFDictionary)
        let status = SecItemAdd(query as CFDictionary, nil)
        guard status == errSecSuccess else {
            throw NSError(domain: NSOSStatusErrorDomain, code: Int(status))
        }
    }

    static func readToken(account: String = "authToken") throws -> String {
        let query: [String: Any] = [
            kSecClass as String: kSecClassGenericPassword,
            kSecAttrAccount as String: account,
            kSecReturnData as String: true,
            kSecMatchLimit as String: kSecMatchLimitOne
        ]

        var item: CFTypeRef?
        let status = SecItemCopyMatching(query as CFDictionary, &item)
        guard status == errSecSuccess,
              let data = item as? Data,
              let token = String(data: data, encoding: .utf8) else {
            throw NSError(domain: NSOSStatusErrorDomain, code: Int(status))
        }

        return token
    }
}

func authenticateUser(completion: @escaping (Bool) -> Void) {
    let context = LAContext()
    var error: NSError?

    guard context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) else {
        completion(false)
        return
    }

    context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics,
                           localizedReason: "Unlock your secure session") { success, authError in
        if let laError = authError as? LAError {
            switch laError.code {
            case .userCancel, .authenticationFailed:
                completion(false)
            default:
                completion(false)
            }
            return
        }
        completion(success)
    }
}

func saveProtectedFile(_ data: Data, to url: URL) throws {
    try data.write(to: url, options: .completeFileProtection)
}
```

Use this as the baseline:

- Store tokens and PII in Keychain with `SecItemAdd` / `SecItemCopyMatching`, not `UserDefaults`
- Gate sensitive actions with `LAContext` and check `canEvaluatePolicy` first
- Write sensitive files with `.completeFileProtection`
- Keep App Transport Security enabled
- Avoid logging tokens or PII in release builds
- Add certificate pinning for production network traffic

Files in this skill

  • eval-1.baseline.md1.3 KB
  • eval-1.with-skill.md945 B
  • eval-2.baseline.md1.5 KB
  • eval-2.with-skill.md1.2 KB
  • eval-3.baseline.md1.2 KB
  • eval-3.with-skill.md2.7 KB
  • trigger-1.md200 B
  • trigger-2.md182 B
  • trigger-3.md125 B
  • trigger-4.md159 B
  • trigger-5.md165 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…