swift-security

Implement secure credential storage with Keychain, Secure Enclave, and CryptoKit on Apple platforms.

Updated Jun 5, 2026
One-click install
npx skills add https://github.com/harshav167/build-ios-apps --skill swift-security-harshav167
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: swift-security
Source: https://github.com/harshav167/build-ios-apps/tree/main/skills/swift-security
Command: npx skills add https://github.com/harshav167/build-ios-apps --skill swift-security-harshav167

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Swift-Security provides a comprehensive, battle-tested approach to secure credential handling on Apple platforms, focusing on binding secrets to hardware-backed protections and preventing AI-generated insecure patterns such as storing tokens in UserDefaults or gating sensitive data behind a simple biometric check.

Core Features & Use Cases

  • Keychain-bound secrets: store tokens, keys, and credentials with explicit SecAccessControl flags and device-bound accessibility.
  • Biometric gating + Secure Enclave: leverage biometric authentication to unlock keychain items protected by the Secure Enclave.
  • CryptoKit integration: perform signing, key agreement, and post-quantum considerations with modern cryptography primitives.
  • Lifecycle patterns: add-or-update semantics, enrollment-change handling, and robust error handling for production-grade credential management.
  • Cross-platform guidance: aligns with Apple Platform Security Guide, OWASP/MASVS MAStG mappings, and established credential-storage patterns.

Quick Start

Store a secret in the Keychain with biometric protection and retrieve it via a biometric-guarded query.

Quick Start

Configure the Keychain query with SecAccessControl, insert the secret, and read it back through SecItemCopyMatching with biometric prompts when required.

-- Note: The Quick Start section above is a plain instruction line to illustrate the intended workflow; implementers should adapt the steps to their app architecture and security requirements.

Quick Start

Perform a biometric-protected read of a credential from the Keychain using a SecItemCopyMatching query that relies on SecUseAuthenticationContext and a SecAccessControl ACL.

Frequently Asked Questions about swift-security

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I store credentials in the iOS Keychain with biometric protection?▼

Store credentials in the iOS Keychain by configuring a query with SecAccessControl flags to require biometric authentication, inserting the secret via SecItemAdd, and reading it back through SecItemCopyMatching with a SecUseAuthenticationContext prompt.

What is the best way to secure Swift tokens without using UserDefaults?▼

Securing Swift tokens without UserDefaults requires binding them to hardware-backed Keychain protections using SecAccessControl, device-bound accessibility flags, and the Secure Enclave to prevent unauthorized access to sensitive credential data.

Can I use CryptoKit for key agreement and signing alongside Secure Enclave keys?▼

Yes, CryptoKit integration supports performing cryptographic signing and key agreement operations, while the Secure Enclave handles hardware-backed key protection to ensure secrets remain isolated from the main application processor.

How does Keychain access control handle biometric enrollment changes on macOS?▼

Keychain access control handles biometric enrollment changes by enforcing lifecycle patterns that detect identity modifications, requiring add-or-update semantics to re-establish credential accessibility and prevent stale biometric gating.

Are there limitations to using Secure Enclave keys for cross-platform credential storage?▼

Secure Enclave keys are hardware-bound to specific Apple devices, meaning credential storage cannot sync across platforms without non-backup constraints, requiring robust error handling for cross-platform iOS and macOS alignment.